Issues with Sound setMicrosecondPosition in Mac Os X
Hi All
I am trying to implement sound player in Java as following.
After completion of play LineEvent.Type.STOP is fired.
Method call soundClip.getMicrosecondPosition() displays the proper values in windows but in Mac OSX it always prints 0.
Please help me out
Thanks in advance
-Surendhar
Re: Issues with Sound setMicrosecondPosition in Mac Os X
Please surround your code with highlight tags (see my sig for how to do this).
What is soundClip? It is entirely possible that between different implementations of the JVM there can be discrepencies in the behavior of certain functions, particularly when regarding "os-specific" components such as sound, video, GUI interfaces, etc. (I believe the JVM on Macs is implemented by Apple rather than Sun/Oracle, not completely positive about this).
Re: Issues with Sound setMicrosecondPosition in Mac Os X
'soundClip' is instance of
Code Java:
javax.sound.sampled.Clip.
Is there any other way to know whether playing sound is completed?
OR
Do we have any other API to play .wav files.
Please share your comments
Thanks
Surendhar
Re: Issues with Sound setMicrosecondPosition in Mac Os X
Well, instead of trying to get soundClip's position, LineEvent has a frame position which records where the event occured. Note that this doesn't necessarily represent real time, so you'll need to convert it into seconds/milliseconds.
Code Java:
public void update(LineEvent event)
{
if(event.getType() == LineEvent.Type.STOP)
{
System.out.println("play complete event: " + (double)(event.getFramePosition() * soundClip.getMicroSecondLength()) / soundClip.getFrameLength());
}
}
There are other sound API's used in "gaming libraries", such as LWJGL (Light-weight Java Gaming Library) and JOAL (Java OpenAL), if you want you can give them a go.
Re: Issues with Sound setMicrosecondPosition in Mac Os X
Thanks a lot for your reply.
I have also the approach you suggested, but it doesn't work for Mac.
Do we any other built-in API to play Sound, because I don't want to use any third party libraries.
Thanks
Surendhar
Re: Issues with Sound setMicrosecondPosition in Mac Os X
As far as I know, no (at least not for sampled sound, there's the Midi API but that's for a different purpose). What is possible is that this a bug with the apple implementation (perhaps a resource is getting unloaded or the values aren't getting updated correctly). Have you tried debugging/stepping through your code to try and see where something could possibly be going wrong?
If you're feeling bold, you can use JNI to provide the functionality you need, but this would amount to basically the same thing as using 3rd party libraries, and you will also need custom native code for every system your program is going to be running on. It's much easier to use a 3rd party library.