Java Reference
In-Depth Information
The getAudioClip() method returns immediately, whether or not the URL
resolves to an actual audio file. The audio file is not downloaded until an
attempt is made to play the audio clip.
The following AudioDemo applet demonstrates playing an audio clip that
is specified as an applet parameter. Study the class, and try to determine how
it looks and what it does.
import java.applet.*;
import java.awt.*;
import java.net.*;
public class AudioDemo extends Applet
{
private AudioClip clip;
private AppletContext context;
public void init()
{
context = this.getAppletContext();
String audioURL = this.getParameter(“audio”);
if(audioURL == null)
{
audioURL = “default.au”;
}
try
{
URL url = new URL(this.getDocumentBase(), audioURL);
clip = context.getAudioClip(url);
}catch(MalformedURLException e)
{
e.printStackTrace();
context.showStatus(“Could not load audio file!”);
}
}
public void start()
{
if(clip != null)
{
clip.loop();
}
}
public void stop()
{
if(clip != null)
{
clip.stop();
}
}
}
Search WWH ::




Custom Search