use of java.applet.AudioClip in project algs4 by kevin-wayne.
the class StdAudio method playApplet.
// play sound file using Applet.newAudioClip();
private static void playApplet(String filename) {
URL url = null;
try {
File file = new File(filename);
if (file.canRead())
url = file.toURI().toURL();
} catch (MalformedURLException e) {
throw new IllegalArgumentException("could not play '" + filename + "'", e);
}
// URL url = StdAudio.class.getResource(filename);
if (url == null) {
throw new IllegalArgumentException("could not play '" + filename + "'");
}
AudioClip clip = Applet.newAudioClip(url);
clip.play();
}
use of java.applet.AudioClip in project algorithms-learning by brianway.
the class StdAudio method play.
/**
* Plays an audio file (in .wav, .mid, or .au format) in a background thread.
*
* @param filename the name of the audio file
*/
public static void play(String filename) {
URL url = null;
try {
File file = new File(filename);
if (file.canRead())
url = file.toURI().toURL();
} catch (MalformedURLException e) {
e.printStackTrace();
}
// URL url = StdAudio.class.getResource(filename);
if (url == null)
throw new RuntimeException("audio " + filename + " not found");
AudioClip clip = Applet.newAudioClip(url);
clip.play();
}
use of java.applet.AudioClip in project Spark by igniterealtime.
the class AlertManager method startAlert.
public void startAlert(String alertResourceName) {
AudioClip alertClip = getAlertClip(alertResourceName, true);
if (alertClip == null) {
return;
}
boolean loop = true;
if (!loop) {
alertClip.play();
} else {
alertClip.loop();
}
}
use of java.applet.AudioClip in project Spark by igniterealtime.
the class SoundManager method loadClipForURL.
/**
* Creates an AudioClip from a URL.
*
* @param clipOfURL the url of the AudioClip to play. We only support .wav files at the moment.
* @return the AudioFile found. If no audio file was found,returns null.
*/
private AudioClip loadClipForURL(String clipOfURL) {
final URL url = SoundsRes.getURL(clipOfURL);
AudioClip clip = null;
try {
clip = Applet.newAudioClip(url);
} catch (Exception e) {
Log.error("Unable to load sound url: " + url + "\n\t: " + e);
}
return clip;
}
use of java.applet.AudioClip in project WorkspaceJava by fdepablo.
the class SoundTest method main.
public static void main(String[] args) throws Exception {
// System.out.println("1");
// URL url = new URL("http://www.edu4java.com/es/game/sound/back.wav");
// System.out.println("2");
// AudioClip clip = Applet.newAudioClip(url);
// System.out.println("3");
// clip.play();
// System.out.println("4");
// Thread.sleep(1000);
// URL url = new URL(
// "file:/C:/eclipseClasic/workspace/minitennis/src/com/edu4java/minitennis7/back.wav");
URL url = SoundTest.class.getResource("applause_y.wav");
AudioClip clip = Applet.newAudioClip(url);
AudioClip clip2 = Applet.newAudioClip(url);
clip.play();
Thread.sleep(1000);
clip2.loop();
Thread.sleep(20000);
clip2.stop();
System.out.println("end");
}
Aggregations