Ex:No:5 Multimedia-Api 29:1:2011
Ex:No:5 Multimedia-Api 29:1:2011
29:1:2011
AIM:
To implement MM application using MM-API in wireless toolkit.
SOURCE CODE:
AUDIO CODE:
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import javax.microedition.media.*;
import java.io.*;
public class mmMIDlet extends MIDlet implements CommandListener
{
private Display display; // Reference to display object
private Form fmMain; // Main form
private Command cmExit; // Command to exit the MIDlet
private Command cmPlay; // Command to play wav file
public mmMIDlet()
{
display = Display.getDisplay(this);
cmExit = new Command("Exit", Command.EXIT, 1);
cmPlay = new Command("Play", Command.SCREEN, 2);
fmMain = new Form("Play audio file");
fmMain.addCommand(cmExit);
fmMain.addCommand(cmPlay);
fmMain.setCommandListener(this);
}
public void startApp()
{
display.setCurrent(fmMain);
}
public void pauseApp()
{}
public void destroyApp(boolean unconditional)
{}
public void commandAction(Command c, Displayable s)
{
if (c == cmExit)
{
destroyApp(false);
notifyDestroyed();
}
else if (c == cmPlay)
playwavfile();
}
public void playwavfile()
{
try
{
InputStream in = getClass().getResourceAsStream
("/bong.wav");
Player p = Manager.createPlayer(in, "audio/x-wav");
p.start();
}
catch (Exception e)
{
Alert alr = new Alert("Error", "Unable to play WAVfile!",
null,AlertType.ERROR);
alr.setTimeout(Alert.FOREVER);
display.setCurrent(alr, fmMain);
}
}
}
VIDEO CODE:
import javax.microedition.media.control.*;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import javax.microedition.media.*;
import java.io.*;
public class videoMIDlet extends MIDlet implements CommandListener
{
private Display display; // Reference to display object
private Form fmMain; // Main form
private Command cmExit; // Command to exit the MIDlet
private Command cmPlay; // Command to play wav file
private Command cdPlay; // Command to play wav file
private static Player player = null;
public videoMIDlet()
{
display = Display.getDisplay(this);
cmExit = new Command("Exit", Command.EXIT, 1);
cmPlay = new Command("Play", Command.SCREEN, 2);
cdPlay = new Command("Pause", Command.SCREEN, 2);
fmMain = new Form("Play video file");
fmMain.addCommand(cmExit);
fmMain.addCommand(cmPlay);
fmMain.addCommand(cdPlay);
fmMain.setCommandListener(this);
}
public void startApp()
{
display.setCurrent(fmMain);
}
public void pauseApp()
{}
public void destroyApp(boolean unconditional)
{}
public void commandAction(Command c, Displayable s)
{
if (c == cmExit)
{
destroyApp(false);
notifyDestroyed();
}
else if (c == cmPlay)
playwavfile();
else if(c == cdPlay)
pause();
}
public void playwavfile()
{
try
{
InputStream in = getClass().getResourceAsStream
("phantom.mpg");
Player p = Manager.createPlayer(in, "video/mpeg");
p.realize();
VideoControl video = (VideoControl) p.getControl
("VideoControl");
Item videoItem = (Item)video.initDisplayMode(
VideoControl.USE_GUI_PRIMITIVE, null);
fmMain.append(videoItem);
p.start();
}
catch(Exception e)
{}
}
public void pause()
{
if ( player != null)
{
try
{
player.stop();
}
catch (MediaException me)
{
System.err.println(me);
}
}
}
}
OUTPUT:
AUDIO:
RESULT:
Thus both audio and video applications are devolped in MM-API usins wireless toolkit.