Java by API/java.awt/AudioClip

Материал из Java эксперт
Перейти к: навигация, поиск

AudioClip: play()

import java.applet.Applet;
import java.applet.AudioClip;
import java.net.URL;
public class MainClass {
  public static void main(String[] args) {
    try {
      URL url = new URL("file:youraudiofile.wav" );
      AudioClip ac = Applet.newAudioClip(url);
      ac.play();
      System.out.println("Press any key to exit.");
      System.in.read();
      ac.stop();
    } catch (Exception e) {
      System.out.println(e);
    }
  }
}





AudioClip: stop()

import java.applet.Applet;
import java.applet.AudioClip;
import java.net.URL;
public class MainClass {
  public static void main(String[] args) {
    try {
      URL url = new URL("file:youraudiofile.wav" );
      AudioClip ac = Applet.newAudioClip(url);
      ac.play();
      System.out.println("Press any key to exit.");
      System.in.read();
      ac.stop();
    } catch (Exception e) {
      System.out.println(e);
    }
  }
}