Play a WAV audio file (this howto is deprecated)

From CodeCodex

Revision as of 08:28, 18 August 2009 by Techmind (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Implementations

Java

<highlightsyntax language="java122"> import com.ms.win32.Winmm; import com.ms.win32.wins;

public class WavAudio {

 private String wavFile=null;
 public WavAudio(String file) {
   wavFile=file;
   }
 public void stop() {
   Winmm.PlaySound(null,0,
      wins.SND_ASYNC|wins.SND_FILENAME|wins.SND_NOWAIT);
   }
 public void playAsync() {
   stop();
   Winmm.PlaySound(wavFile,0,
     wins.SND_ASYNC|wins.SND_FILENAME|wins.SND_NOWAIT);
   }
 public void playSync() {
   stop();
   Winmm.PlaySound(wavFile,0,
     wins.SND_SYNC|wins.SND_FILENAME|wins.SND_NOWAIT);
   }
 public void loop() {
   // stop();
   Winmm.PlaySound(wavFile,0,
     wins.SND_ASYNC|wins.SND_LOOP|wins.SND_FILENAME|wins.SND_NOWAIT);
   }
    
 public static void main(String args[]) {
   // for demonstration ...
      WavAudio ac = 
       new WavAudio("c:/windows/media/Chord.wav");
   System.out.print("Playing ...");
   ac.playSync();
   System.out.println("Done...");
 }

} </highlightsyntax>