Thread friendly MP3/OGG playback

J

James Harvey

Hi all,

I am working on a graphical demo. I am experimenting with the JLayer
library from JavaZoom (http://www.javazoom.net/projects.html) for
playing MP3s. The playback quality seems very nice.

It seems that the Player.play() method blocks until playback completes,
so I decided to wrap it in a thread:

private class PlayerThread extends Thread
{
private Player player;

public PlayerThread(Player player)
{
this.player = player;
}

public void run()
{
try
{
player.play();
System.out.println("PLAYBACK COMPLETE");
}
catch (JavaLayerException ex)
{
ex.printStackTrace();
}
}

public void stopPlayback()
{
player.close();
}

}

This works, but this thread seems to affect the performance of my main
thread quite badly. Without having looked at the source of JLayer (yet),
I'm guessing that it doesn't play nice by yield()ing.

Can anybody suggest:

1) A way to decrease the performance hit from this thread. Possibly
decode the MP3 to raw audio before the application proper starts?

2) A nice lightweight MP3 or Ogg Vorbis library for Java that runs
nicely in its own thread. All I need is simple load(), play(), stop()
functionality. I have found quite a few but if anybody can point me in
the right direction without having to evaluate them all it would be much
appreciated.

Thank you,

Bruce.
 
D

Douwe

You could use the setPriority method of the Thread class to decrease
the Player's priority or to increase the main-thread's priority, but I
don't think that will bring much. Normaly all processor power that is
"unused" by the system can be spent on your Java program. So in the
case your main Thread is running slow it should also mean that your
System's load is on 100% you should check if that is the case. If you
are running Javazoom on a WindowsNT with no Service Pack and use a
JDK1.3.1 or less then this is probably your problem.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top