Java Reference
In-Depth Information
Code 4.2
Playing functionality of
the MusicOrganizer
class
import java.util.ArrayList;
/**
* A class to hold details of audio files.
* This version can play the files.
*
* @author David J. Barnes and Michael K├Âlling
* @version 2011.07.31
*/
public class MusicOrganizer
{
// An ArrayList for storing the file names of music files.
private ArrayList<String> files;
// A player for the music files.
private MusicPlayer player;
/**
* Create a MusicOrganizer
*/
public MusicOrganizer()
{
files = new ArrayList<String>();
player = new MusicPlayer();
}
/**
* Start playing a file in the collection.
* Use stopPlaying() to stop it playing.
* @param index The index of the file to be played.
*/
public void startPlayingFile( int index)
{
String filename = files.get(index);
player.startPlaying(filename);
}
/**
* Stop the player.
*/
public void stopPlaying()
{
player.stop();
}
Other details omitted.
}
Search WWH ::




Custom Search