0

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 ?

Frank
  • 30,590
  • 58
  • 161
  • 244

2 Answers2

2

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

Frank
  • 30,590
  • 58
  • 161
  • 244
0

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.

Brian Beckett
  • 4,742
  • 6
  • 33
  • 52
  • Shouldn't one use the desktop objects to start said .wav file vs. relying on OS-specific semantics. – Jé Queue Nov 10 '09 at 15:08
  • 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. – Brian Beckett Nov 10 '09 at 18:29
  • 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 Nov 12 '09 at 18:27
  • 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. – Brian Beckett Nov 12 '09 at 18:52
  • 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 Nov 12 '09 at 19:19