FileDocCategorySizeDatePackage
AudioPlayer.javaAPI DocJ2ME MIDP 2.03059Thu Nov 07 12:02:20 GMT 2002example.audiodemo

AudioPlayer

public class AudioPlayer extends MIDlet implements CommandListener
This is a demo midlet to show the basic audio functionalities, to play wave file, tone, tone sequence from http, resource jar file and record store.
author
Sharon.Huang@Sun.Com

Fields Summary
private static PlayerCanvas
playerGUI
private static List
theList
private static Vector
urls
private Command
exitCommand
private Command
playCommand
private Display
display
Constructors Summary
public AudioPlayer()


    
      
	super();
    
Methods Summary
public voidcommandAction(Command c, Displayable s)

        if (c == exitCommand) {
            destroyApp(true);
            notifyDestroyed();
       } else if ((s == theList && c == List.SELECT_COMMAND) ||
		  c == playCommand) {
	   int i = theList.getSelectedIndex();
	   if (i == 0) { // Simple tone
	       try {
		   Manager.playTone(60, 200, 90);
	       } catch (MediaException ex) {
		   System.out.println("can't play tone");
	       }
	   } else if (i > 0) {
	       if (playerGUI == null) 
		   playerGUI = new PlayerCanvas(display);
	       else 
		   playerGUI.stopSound();

	       playerGUI.setParam((String) urls.elementAt(i));
	       playerGUI.playSound();
	       display.setCurrent(playerGUI);
	   }
       }
    
public voiddestroyApp(boolean unconditional)

	if (playerGUI != null) {
	    playerGUI.stopSound();
	    playerGUI = null;
	}
	display.setCurrent(null);
    
public static java.util.ListgetList()

	return theList;
    
private voidinitPlayList()
load the play list from thd jad file

	urls = new Vector();

	theList  = new List("MIDP Audio Player", Choice.IMPLICIT);

	for (int n = 1; n < 32; n++) {
	    String nthURL = "PlayerURL-"+ n;
	    String url = getAppProperty(nthURL);
	    if (url == null || url.length() == 0) {
		break;
	    }
            String nthTitle = "PlayerTitle-" + n;
            String title = getAppProperty(nthTitle);
            if (title == null || title.length() == 0) {
		title = url;
	    }
            urls.addElement(url);
            theList.append(title, null);
	}
	
        theList.addCommand(exitCommand);
        theList.addCommand(playCommand);
	theList.setCommandListener(this);
    
public voidpauseApp()

    
public voidstartApp()

	display  = Display.getDisplay(this);
	initPlayList();
	display.setCurrent(theList);