在java中播放“* .mp3”文件的最佳方法是什么?

时间:2011-01-03 14:57:35

标签: java mp3 jmf mplayer vlcj

我可以使用VLC或MPlayer的接口吗? 我只想要一个能够在linux机器上播放歌曲的界面(Servlet - > Java)。

致以最诚挚的问候,

3 个答案:

答案 0 :(得分:1)

似乎这就是你想要的,JLayer

答案 1 :(得分:1)

VLC jas Java bindings。以下是docs的示例:

String[] libvlcArgs = {...add options here...};
MediaPlayerFactory mediaPlayerFactory = new MediaPlayerFactory(libvlcArgs);
FullScreenStrategy fullScreenStrategy = new DefaultFullScreenStrategy(mainFrame);
EmbeddedMediaPlayer mediaPlayer = mediaPlayerFactory.newMediaPlayer(fullScreenStrategy);
String[] standardMediaOptions = {"video-filter=logo", "logo-file=vlcj-logo.png", "logo-opacity=25"}; 
mediaPlayer.setStandardMediaOptions(standardMediaOptions);
mediaPlayer.addMediaPlayerEventListener(new MediaPlayerEventAdapter() {...add implementation here...});
Canvas videoSurface = new Canvas();
mediaPlayer.setVideoSurface(videoSurface);
String mediaPath = "/path/to/some/movie.mpg";
String[] mediaOptions = {};
mediaPlayer.playMedia(mediaPath, mediaOptions);
// Do some interesting things in the application
...
mediaPlayer.release();
mediaPlayerFactory.release();

答案 2 :(得分:1)

此任务不需要JMF。只需将JMF的mp3plugin.jar添加到应用程序的运行时类路径中即可。然后,Java声音将能够读取和播放MP3。

您也可以查看Java Bindings for VideoLAN

无论哪种方式,都需要applet或JWS启动的应用程序。