Java音乐播放器:歌曲信息和播放 [英] Java Music Player: Song information and playing

查看:318
本文介绍了Java音乐播放器:歌曲信息和播放的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Android中,我们可以使用媒体播放器在设备上播放歌曲,使用光标来获取曲目信息(操作系统会跟踪)。我的问题是,这些Java的等价物是什么?



注意:我看到有人提到JavaFX,但是默认情况下这似乎没有安装JVM和因此,我的程序将不再是跨平台的。



有任何建议吗?



注意:这些都是本地文件,但它们可能是任何音频文件类型。

解决方案

我将提供有关Java的JavaFX相关解决方案的信息音乐播放器我​​认为这是一项很好的技术用于此任务。



支持的平台和格式


它们可能是任何音频文件类型。


支持JavaFX的音频类型记录在由 Pro JavaFX 2 book 的作者创建。这可能是比我的代码更好的参考,因为我的是快速黑客,而专业来源是专业出版的书。



其他问题


我们这些人在linux上没有使用Oracle的JRE的任何建议?


Oracle JRE在Linux上可用,但如果您不想使用它,则可以构建 openjdk 的OpenJFX / Mainrel =nofollow noreferrer> openjfx 并使用它,或者您可以使用Oracle JRE开发您的应用程序,并使用JavaFX打包工具将其分发为自包含应用程序因此它没有外部JRE依赖。


In Android, we can use the mediaplayer to play songs on the device, and cursors to get the track information (which the OS keeps track of). My question is, what are the Java equivalents of these?

Note: I have seen people mentioning JavaFX, however this does not seem to be installed with the JVM by default and thus my program would no longer be cross-platform.

Any suggestions?

Note: These will all be local files, though they may be of any audio filetype.

解决方案

I'll provide information on a JavaFX related solution for a Java music player as I think it is a good technology to use for this task.

Supported Platforms and Formats

they may be of any audio filetype.

Supported audio types for JavaFX are documented in the javafx.scene.media javadoc. Supported formats for JavaFX 2.2 are MP3, AAC and PCM in various containers such as mp3, mp4 and wav files. Other formats such as Ogg Theora are not supported - so if you need such formats you will need a different solution than JavaFX 2.2.

I have seen people mentioning JavaFX, however this does not seem to be installed with the JVM by default and thus my program would no longer be cross-platform

JavaFX is installed with the Oracle Java runtime by default since Java 7 update 6 and JavaFX 2.2 runs on OS X, Windows and Linux. There are currently no widely available solutions for running JavaFX on mobile platforms (though that may change in the future).

Further information on using JavaFX with Java 7 is in my answer to Compiling and running with JavaFX 2.1 as well as the JavaFX Deployment Guide.

get the track information (which the OS keeps track of)

Most track information is actually encoded in media files rather than in an OS database. You can retrieve metadata from media files played by JavaFX. Parsing of a limited amount of metadata from media files is supported as defined in the media documentation. Note that not all media contains all metadata. I tested a free mp3 file from amazon and was able to extract plenty of metadata from it successfully. Metadata from a test aac encoded m4a file from iTunes was mostly empty. So results depend on the media file being used.

Sample Player

I created a sample music player in JavaFX which plays audio files from a directory, displaying metadata for each song.

java2s also host source for a media player created by the authors of the Pro JavaFX 2 book. That might be a better reference than my code, as mine was a quick hack, whereas the pro source is from a professionally published book.

Additional Questions

Any suggestions for those of us on linux not using Oracle's JRE?

Oracle JRE is available on Linux, but if you don't want to use that, you can build openjfx for openjdk and use that, or you could develop your app using Oracle JRE and use the JavaFX packaging tools to distribute it as a self-contained application so it has no external JRE dependency.

这篇关于Java音乐播放器:歌曲信息和播放的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆