开发者

pausing mp3 in java

开发者 https://www.devze.com 2023-02-25 16:37 出处:网络
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

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 lib开发者_JAVA技巧rary (link here), but i always end up getting javax.sound.sampled.UnsupportedAudioFileException when trying to read any mp3 file


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号