I'm trying to run audio in a different thread but I have no idea why but when I call wait(), my entire program seems to wait or hang.. not sure if it's deadlock since all it does is wait(), though if I set a time period, after that period it'll work again meaning it isn't running on a different thread? since my main thread stops when I tell the other thread to wait.. I've been searching the net without any results.. read on synchronization, locks, deadlocks(wondering if this is the problem) but to no avail...
nothing has helped so far at least.. since it's waiting for a notify from the main thread using the lock object(which is synchronized with it), but since the main thread seems to wait and not work with that thread... well.. you can see it's stuck..
code for the thread is
class play implements Runnable
{
public synchronized void run()
{
synchronized(lock)
{
try{
AudioInputStream stream = AudioSystem.getAudioInputStream(ClassLoader.getSystemClassLoader().getResource("ssbgm.wav"));
DataLine.Info info = new DataLine.Info(Clip.class, stream.getFormat());
Clip clip = (Clip) AudioSystem.getLine(info);
clip.open(stream);
clip.start();
this.wait();
clip.close();
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
}
and the main is connected to a mouse listener in a customized JButton class in a JPanel object in a JFrame Window that main creates.. then it calls that thread and supposedly, when I click the JButton, it will notify that thread
though how do I make it lock again since the lock gets released when I call wait, just curious since I can just use this.wait for a synchronized thread but just wondering how to make an object a lock again
PPS: any good way for playing audio files(preferably mp3) in java? the ones scattered on the net use the sun media player and audiostream objects if I remember correctly, which have access restrictions placed on them so I can't use them. Also, everything I found on the net about audio streaming is rather.. confusing with some methods contradicting others.. no idea what to do.. and my method.... sucks.. bad... not only does .wav multiply my filesize by God knows how many times.. but the buffer size is so freakin small... had to convert a 1:37 192kbps stereo mp3 to a 8kpbs 11000hz mono wav just so it would fit the buffer... and it sounds absolutely horrible.. so any help with that would be greatly.. greatly appreciated as well...
PPS: Sorry if it's super noob coding.. I just started really learning java 2 days ago, at least I caught on to animation and timers at least(have a timer that paints all objects in a vector, objects are instances of a class I made that stores all sprites and animations in arrays that are easily incremented and looped by the timer, works well with motion as well and the overhead isn't so bad). Anyways, sorry if I'm doing something really stupid since.. nothing I find on the net really helps.. and sorry for wasting your time... thanks in advance :D