我目前正在开发一个项目,需要播放背景 mp3 声音。我设法使用 Jlayer 库和此处
但是,我需要向此代码添加更多功能,例如循环播放和暂停。
循环功能相当容易实现,但我花了几个小时寻找暂停和恢复 mp3 文件的方法。
我的猜测是使用 Player 类中的 play(intframes) 方法,使用 getPosition() 方法和 mp3 总帧数,但我无法获取总帧数。
有什么线索吗?我只需要这个暂停/恢复方法,所以如果您知道一种与此不同的方法,请随时发布
我也一直在尝试使用 BasicPlayer 库的一些东西(链接 这里),但在尝试读取任何 mp3 文件时我总是得到 javax.sound.sampled.UnsupportedAudioFileException
I'm currently working on a project in which i need to play a background mp3 sound. I managed to do that using the Jlayer library and a piece of code found here
However, I needed to add some more features to this code, such as loop playing and pause.
The loop function was fairly easy to implement, but i've spent hours looking for a way to pause and resume mp3 files.
My guess would have been to use the play(int frames) method in the Player class, using the getPosition() method and the mp3 total frame number, but i can't manage to get the total frame number.
Any clue ? I just need this pause/resume method, so if you know one way different from this, feel free to post
i've also been trying some stuff with the BasicPlayer library (link here), but i always end up getting javax.sound.sampled.UnsupportedAudioFileException when trying to read any mp3 file
发布评论
评论(2)
您无法使用默认播放器实现来做到这一点。
您需要实现流类并读取这些 DataSourceLine 类的数据。
这有点困难,但这是可能的。我两年前做过,如果我找到了我的代码,我会把它发布给你。
You can't do that with the Default Player implementation.
You need to implement the stream classes and read data which those DataSourceLine classes.
It's a bit hard work, but it's possible. I did it 2 years ago, if I found my code I post it to you.
标准 Java Sound 提供了问题中所述的所有功能。要向 Java Sound 添加 MP3(解码)支持,请添加 mp3plugin.jar(JMF 的)到应用程序的运行时类路径。
Standard Java Sound provides all the functionality stated in the question. To add MP3 (decoding) support to Java Sound, add the mp3plugin.jar (of the JMF) to the run-time class-path of the application.