You are on page 1of 16

Mobile Media API - MMAPI

Session 3
Trinh Thi Van Anh PTIT 1-2013

Objectives
Music files The player's life-cycle Content Types Displaying Video Case study 2

Session 3/ 2 of 22

MMAPI

The MMAPI is built on a high-level abstraction of all the multimedia devices that are possible in a resource-limited device. Three classes are the Player and Control interfaces, and the Manager class. Another class, the DataSource abstract class, is used to locate resources, but unless you define a new way of reading data you will probably never need to use it directly.

Session 3/ 3 of 22

Player creation and management

Session 3/ 4 of 22

Music files

Create a Player from Manager Sampling audio from web server private void playViaHttp() { URL url = "http://65.215.221.148:8080/wj2/res/relax.wav"; Player p = Manager.createPlayer(url); p.start(); } Sampling audio locally stored private void playFromResource(){ InputStream in = getClass().getResourceAsStream("/relax.wav"); Player player = Manager.createPlayer(in, "audio/x-wav"); player.start();}
Session 3/ 5 of 22

Streaming

public class J2MENetworkTest extends MIDlet implements Comm andListener { private List list = new List("Press Play", List.IMPLICIT); private Display display; public J2MENetworkTest() { list.addCommand(new Command("Exit", Command.EXIT, 1)); list.addCommand(new Command("Play", Command.SCREEN, 1)); list.setCommandListener(this); display = Display.getDisplay(this); } public void startApp() { display.setCurrent(list); } public void pauseApp() { } public void destroyApp(boolean unconditional) { }
Session 3/ 6 of 22

public void commandAction(Command cmd, Displayable d isp) { if (cmd.getLabel().equals("Exit")) { notifyDestroyed(); } else { try { Player player = Manager.createPlayer("http://www.y oursite.com/s.wav"); player.start(); } catch (Exception e) { System.err.println(e); }} }
Session 3/ 7 of 22

The player's life-cycle

the player is in an UNREALIZED state and must be REALIZED and PREFETCHED before it can be STARTED. Good programming practice requires that you call the realize() and prefetch() methods before you call the start() method

Session 3/ 8 of 22

To this end, a Player instance allows you to attach a PlayerListener by using the method Almost all transitions states are notified to the listener via the method playerUpdate(Player player, String event, Object eventData).

Session 3/ 9 of 22

Locally Stored (playaudio)

public class J2MESimplePlayer extends MIDlet { public void startApp() { try { Player player = Manager.createPlayer(getClass().getResou rceAsStream("/filename.wav"), "audio/x-wav"); player.start(); } catch (Exception e) { e.printStackTrace(); }} public void pauseApp() {} public void destroyApp(boolean unconditional) { }}
Session 3/ 10 of 22

Supported Content Types and Protocols (playtypes)

a MediaException will be thrown if ask cant handle protocol Two methods in the Manager class: public static String [] getSupportedContentTypes(String protocol) public static String [] getSupportedProtocols(String content_type) null to either of these methods, youll get a complete list of supported content types or protocols

Session 3/ 11 of 22

MMAPI supports several audio and video formats: Audio:

File Ware: audio/x-wav file AU: audio/basic file Mp3: audio/mpeg file Midi: audio/midi Tone sequences: audio/x-tone-seq

Video: MPEG-1
Session 3/ 12 of 22

Music files (play)

Beyond the Player interface is a whole world of Controls obtain a list of Controls for a Player by calling getControls() returns an array of Controls Obtain just one control, pass its name to Players getControl() method VolumeControl vc = (VolumeControl)player.getControl("Volume Control"); vc.setLevel(50);

Session 3/ 13 of 22

Displaying Video (video)

Only difference is displaying the video. Two ways to do this:


On custom Canvas As Item within a Form (VideoControl) vidc = (VideoControl) player.getControl("VideoControl");

Must first get a hold of VideoControl instance

Session 3/ 14 of 22

Case study 2 (Option 1) (album)

Vit chng trnh chi nhc trn mobile vi cc yu cu sau: Danh sch bi ht Chn tng bi iu chnh volume trc quan (dng gauge) Qun l danh sch (danh sch yu thch, th loi) Khc

Session 3/ 15 of 22

Option 2

CHAPTER 9 Case Study: Device Blogging Ebook: Pro java MMAPI

Session 3/ 16 of 22

You might also like