简体   繁体   English

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

[英]What is the best way to play “*.mp3” files in java?

Is there an interface to VLC or MPlayer which I can use?我可以使用 VLC 或 MPlayer 的接口吗? I simply want an interface (Servlet -> Java) which is able to play songs on a linux machine.我只想要一个能够在 linux 机器上播放歌曲的接口 (Servlet -> Java)。

看起来这就是你想要的, JLayer

VLC jas Java bindings . VLC jas Java 绑定 Here's a sample from the 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();

This task does not require JMF.此任务不需要 JMF。 Just add the mp3plugin.jar of the JMF into the run-time class path of the app.只需将 JMF 的 mp3plugin.jar 添加到应用程序的运行时类路径中。 and Java sound will then be able to read and play MP3s.然后 Java 声音将能够读取和播放 MP3。

You might also look at Java Bindings for VideoLAN .您还可以查看VideoLAN 的 Java 绑定

Either way, it will require an applet or JWS launched application.无论哪种方式,它都需要一个小程序或 JWS 启动的应用程序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM