In case you haven't come across them yet, MP3 files are an emmerging strandard for transferring audio files over the Internet. You can buy MP3 players. These are like personal stereos; you download files from the Internet onto the player and can then listen to them as you move around. There are a growing number of MP3 sites such as mp3.com. Although, the following example doesnt explicitly show how to play MP3 files, the Java tutorial says that it is suported (see the tutorial trail and mp3.org).
It consists of the following files:
Task 1: Copy over and run your own version
Repeat the steps that you have followed in previous exercises by copying over the java files and the audio clips. Compile the applet in the usual way and write your own html file to call the copy of the applet in your local workspace.
Important: because you are making use of Swing, it is good practice to use an EMBED tag rather than the APPLET tag that you have used before in your html files. This ensures that your code can be run in browsers that do not already have Swing support. An explanation for this is given in the Java tutorial. In your html file, you must include the line:
< EMBED type="application/x-java-applet;version=1.2" java_CODE ="SoundApplet.class" java_CODEBASE = "../demos/audio" java_ARCHIVE = "playing.jar" WIDTH = "500" HEIGHT = "200" pluginspage="http://java.sun.com/products/plugin/1.2/plugin-install.html"> < /APPLET>< /NOEMBED>< /EMBED>
Task 2: Find/record your own Audio clip and add it to the program
There are numerous audio samples on the web in the file formats supported by the Applet (auFile, aiffFile, midiFile, rmfFile, wavFile). You can download any one of these and update SoundApplet.java to play them. Alternatively, if you have access to a machine with a microphone, you can use the SoundRecorder (look under Start->Programs->Accessories->Multimedia on most NT machines) to record your own samples as a .wav format file.
The initial section provide links to MP3 providers - you could extend the original applet to play some of the files offered by these companies. You will need to download an MP3 file and then alter SoundApplet.java to incorporate the new FileType. Important: please do not infinge copyright restrictions - there is more information about the emmerging debate over MP3 on mp3.org. Your ability to play the sample will depend on whether the Java plugin that this applet calls can recognise the format - it may not work on all browsers.
Back to the main index...