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

From CodeCodex

m (Text replace - "<highlightsyntax " to "<pre ")
m (Text replace - "</highlightsyntax>" to "</pre>")
Line 40: Line 40:
 
   }
 
   }
 
}
 
}
</highlightsyntax>
+
</pre>
  
 
=== Tcl ===
 
=== Tcl ===

Revision as of 00:39, 7 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...");
  }
}

Tcl

package require snack
snack::sound s -load c:/windows/media/Chord.wav
s play