0% found this document useful (0 votes)
299 views

Ex:No:5 Multimedia-Api 29:1:2011

The document describes source code for developing multimedia applications using the Multimedia API (MM-API) in the wireless toolkit. It includes code for playing audio and video files. The audio code plays a WAV file and handles errors if the file cannot be played. The video code plays an MPEG file, initializes the display mode, and appends the video to the main form. It also includes commands to play, pause, and exit the application.

Uploaded by

ashleyaa08
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
299 views

Ex:No:5 Multimedia-Api 29:1:2011

The document describes source code for developing multimedia applications using the Multimedia API (MM-API) in the wireless toolkit. It includes code for playing audio and video files. The audio code plays a WAV file and handles errors if the file cannot be played. The video code plays an MPEG file, initializes the display mode, and appends the video to the main form. It also includes commands to play, pause, and exit the application.

Uploaded by

ashleyaa08
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

Ex:No:5 MULTIMEDIA-API

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.

You might also like