views:

360

answers:

2

I have a Java program that auto dials phone numbers, it can generate sounds to mimic phone keypads, works fine for normal calls, but I encountered a problem when it comes to calling card, it requires me to enter a card number, the sounds generated by my program were not accepted by the other end, it always said the card number is incorrect, so I did some research and found a site that would generate the entire card number sound sequence for me, and I saved it, but the thing is when I used the following Java method to play the *.wav sound file, it's still not accepted, and yet if I play the same file back with Windows Media Player, the other end would accept it as a valid card number sound, why ? Does that mean Java Applet play sound file has a different effect than Windows Media Player ?

  void playAudioFile(String File_Name)
  {
    try { Applet.newAudioClip(new URL("file:/"+File_Name)).play(); }
    catch (Exception e) { e.printStackTrace(); }
  }

If so, how can I, in my Java program, call Windows Media Player to play the sound ?

A: 

I can't tell you why exactly you are seeing this effect, but I can tell you how to launch Windows Media Player from your program.

Assuming Windows XP and Windows Media Player 11:

String myCommand = "\"C:\\Program Files\\Windows Media Player\\wmplayer\\\" /open \"" + File_Name + "\""
Runtime.getRuntime().exec(myCommand);

This will launch Windows Media Player and make it play the file that File_Name points to (full path would probably be safest). If Media Player is already open then it will still work :) Any currently playing file will be interrupted.

I hope this helps.

Cosmic Flame
Shouldn't one use the desktop objects to start said .wav file vs. relying on OS-specific semantics.
Xepoch
Certainly, if it's possible to do that.Frank asked for a way to call Windows Media Player to play his sound file. That sounds pretty OS-specific to me. I admit that this isn't the best way to solve this problem, but it is a solution nonetheless.
Cosmic Flame
I tried it under Win Vista, didn't work, no window launched for Windows Media Player and no sound was played, I also tried this :"\"C:\\Program Files\\Windows Media Player\\wmplayer.exe\\\" /open \"" + File_Name + "\""Could Vista be different from XP ?
Frank
Yes, Vista is likely different from XP. Try this: Find the correct path to Windows Media Player and change myCommand to point at the right file. If you right-click on a shortcut to Media Player, you should be able to find the path in the properties window.
Cosmic Flame
Yes, if I do "\"C:\\Program Files\\Windows Media Player\\wmplayer.exe", it will open the WMP without playing any file, but if I specify the file path, it won't open or play anything at all.
Frank
+1  A: 

I tuned up the sound volume, now it works fine.

Frank