3

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

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
Aserre
  • 4,916
  • 5
  • 33
  • 56

2 Answers2

4

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.

Marcos Vasconcelos
  • 18,136
  • 30
  • 106
  • 167
  • Ok thanks for the information ! Would you know if this would be easier to do using ogg files and JOrbis library ?? And if you find your old code, i'll be glad to read it – Aserre Apr 15 '11 at 19:13
  • The work is not MP3 or OGG specific, you can write one Player which will play any file. Also, you can check the code from the open-source player available on JavaZOOM. PS: If my answer was usefull, vote up. This is how StackOverflow works. – Marcos Vasconcelos Apr 15 '11 at 19:17
  • I checked the open-source player, but I only end up getting exceptions. I'll dig it up though. Concerning the vote up, i can't as my reputation is too low – Aserre Apr 15 '11 at 19:34
  • It's a bit hard work, but the code to make a player is there. – Marcos Vasconcelos Apr 15 '11 at 19:37
2

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.

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433