Playing Audio Clips from a JFC Application

How do I create an application that plays audio clips?

The Applet class contains a newAudioClip method that can be called to load an audio clip. Once this audio clip has been loaded, AudioClip's play and stop methods can be called to play this audio clip, and stop playing when necessary. The following Audio2 application demonstrates using newAudioClip to load an audio clip, which is subsequently played.

 // Audio2.java import java.applet.*; import java.net.*; class Audio2 { public static void main (String [] args) { if (args.length != 1) { System.out.println ("usage: java Audio2 url"); return; } try { URL url = new URL ("file:" + args [0]); AudioClip ac = Applet.newAudioClip (url); ac.play (); System.out.println ...

Get Special Edition Using Java 2 Standard Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.