Difference between revisions of "Play a WAV audio file (this howto is deprecated)"

From CodeCodex

(Implementations)
m (Text replace - "<highlightsyntax " to "<pre ")
Line 1: Line 1:
 
==Implementations==  
 
==Implementations==  
 
===Java===  
 
===Java===  
<highlightsyntax language="java122">
+
<pre language="java122">
 
import com.ms.win32.Winmm;
 
import com.ms.win32.Winmm;
 
import com.ms.win32.wins;
 
import com.ms.win32.wins;

Revision as of 20:16, 6 January 2012

Implementations

Java

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>

=== Tcl ===
<pre class="tcl">
package require snack
snack::sound s -load c:/windows/media/Chord.wav
s play