JMF Not playing wav files in Linux

Hi all,

I'm using the code below to play a simple wav file in Linux:

==

import java.io.IOException;

import java.net.MalformedURLException;

import java.net.URL;

import javax.media.ControllerEvent;

import javax.media.ControllerListener;

import javax.media.EndOfMediaEvent;

import javax.media.Manager;

import javax.media.MediaLocator;

import javax.media.NoPlayerException;

import javax.media.Player;

/**

*

* @author

*/

publicclass AudioTestimplements ControllerListener{

/** Creates a new instance of AudioTest */

public AudioTest(){

}

publicstatic Object syncObject =new Object();

publicstaticvoid main(String args[])throws InterruptedException{

try{

URL url =new URL("file","","/magichome/xruser/jmf/WindowsXPStartup.wav");

String mediaFile = url.toExternalForm();

System.out.println(mediaFile);

MediaLocator mediaLocator =new MediaLocator(mediaFile);

System.out.println(mediaLocator);

if(mediaLocator !=null){

try{

AudioTest test =new AudioTest();

//Player player = Manager.createPlayer(mediaLocator);

Player player = Manager.createPlayer(url);

player.addControllerListener(test);

System.out.println(player);

player.start();

synchronized(syncObject){

syncObject.wait();

player.stop();

player.close();

System.out.println("CLosed...");

}

/*

Thread.sleep(10000);

System.exit(0);

**/

}catch (NoPlayerException ex){

ex.printStackTrace();

}catch (IOException ex){

ex.printStackTrace();

}catch (Error err){

err.printStackTrace();

}

}

//com.sun.media.amovie.AMController@9fef6f

}catch (MalformedURLException ex){

ex.printStackTrace();

}

}

publicvoid controllerUpdate(ControllerEvent event){

System.out.println(event);

if (eventinstanceof EndOfMediaEvent){

synchronized(syncObject){

syncObject.notify();

}

}

}

}

==

But on running the above program with the following commands:

/usr/java/j2sdk1.4.2_08/bin/javac -classpath /magichome/xruser/jmf/jmf.jar:./:/magichome/xruser/jmf/mediaplayer.jar:/magichome/xruser/jmf/multiplayer.jar:/magichome/xruser/jmf/sound.jar:customizer.jar AudioTest.java

/usr/java/j2sdk1.4.2_08/bin/java -classpath /magichome/xruser/jmf/jmf.jar:./:/magichome/xruser/jmf/mediaplayer.jar:/magichome/xruser/jmf/multiplayer.jar:/magichome/xruser/jmf/sound.jar:customizer.jar AudioTest

I get the following error:

==

file:/magichome/xruser/jmf/WindowsXPStartup.wav

file:/magichome/xruser/jmf/WindowsXPStartup.wav

com.sun.media.content.unknown.Handler@1ee4648

javax.media.TransitionEvent[source=com.sun.media.content.unknown.Handler@1ee4648,previous=Unrealized,current=Realizing,target=Started]

javax.media.DurationUpdateEvent[source=com.sun.media.content.unknown.Handler@1ee4648,duration=javax.media.Time@1e8a1f6

javax.media.RealizeCompleteEvent[source=com.sun.media.content.unknown.Handler@1ee4648,previous=Realizing,current=Realized,target=Started]

javax.media.TransitionEvent[source=com.sun.media.content.unknown.Handler@1ee4648,previous=Realized,current=Prefetching,target=Started]

Unable to handle format: LINEAR, 22050.0 Hz, 16-bit, Stereo, LittleEndian, Signed, 88200.0 frame rate, FrameSize=32 bits

Failed to prefetch: com.sun.media.PlaybackEngine@91cee

Error: Unable to prefetch com.sun.media.PlaybackEngine@91cee

javax.media.ResourceUnavailableEvent[source=com.sun.media.content.unknown.Handler@1ee4648,message=Failed to prefetch: cannot open the audio device.]

==

I'm unable to isolate the problem here. When I play the file with mplayer, it plays just fine. But with the code above, it just does not wish to play..

Can someone please point out the error I am commiting.

Thanks

[6315 byte] By [Anantja] at [2007-11-27 4:25:04]
# 1

..

> I'm using the code below to play a simple wav file in

> Linux:

I'm running the performance pack under Win XP, here..

...

try {

URL url = new URL("file", "", "/magichome/xruser/jmf/WindowsXPStartup.wav");

...

Is that a linear encoded, 16 bit, stereo sample

recorded at 22050Hz sample rate? 4.81 seconds

(424,644 bytes), content type audio.x_wav?

The reason I ask is just that you do not mention if

you'd tested on any other OS, and I found a very

similarly named WAV of the above description on

my system and tried it with your code - and in

JMStudio.

It ran flawlessly in both.

> But on running the above program

...

> I get the following error:

...

> file:/magichome/xruser/jmf/WindowsXPStartup.wav

> file:/magichome/xruser/jmf/WindowsXPStartup.wav

> com.sun.media.content.unknown.Handler@1ee4648

...

> Unable to handle format: LINEAR, 22050.0 Hz,

> 16-bit, Stereo, LittleEndian, Signed, 88200.0 frame

> rate, FrameSize=32 bits

...

> I'm unable to isolate the problem here. When I play

> the file with mplayer,

What is 'mplayer'? The default media player

of the OS?

>..it plays just fine. But with

> the code above, it just does not wish to play..

>

> Can someone please point out the error I am

> commiting.

I cannot tell what the problem is, sorry. Just

thought I should check in and note there is

nothing wrong with the code, and that WAV

is sure understood by Windows based JMF.

AndrewThompson64a at 2007-7-12 9:33:06 > top of Java-index,Security,Cryptography...
# 2

Hi,

Thanks for the quick reply. And apologies for the confusion.

I'm actually using a wav which comes with the xemacs media pack. I first tried this program on windows and that was the name I used there.

So for Linux, I just changed the file name instead of the source!

On windows, the same filename runs flawlessly with my code and JMStudio

I'm not sure how to check the bit rate of the file but I tried playing the same file with mplayer and it plays. Mplayer is the linux media player available at http://mplayerhq.hu

>

> I cannot tell what the problem is, sorry. Just

> thought I should check in and note there is

> nothing wrong with the code, and that WAV

> is sure understood by Windows based JMF.

Yes, as I mentioned above, windows is not the issue. The file (any wav file) does not play on Linux.

(Sorry, I'm not too familiar with sound on Linux)

Anantja at 2007-7-12 9:33:06 > top of Java-index,Security,Cryptography...