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
169k42 gold badges224 silver badges441 bronze badges
asked Apr 15, 2011 at 19:04

2 Answers 2

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.

answered Apr 15, 2011 at 19:09
Sign up to request clarification or add additional context in comments.

4 Comments

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
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.
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
It's a bit hard work, but the code to make a player is there.
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.

answered Apr 15, 2011 at 19:54

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.