Jump to content

Java Mobile Media API

From Alfawiki
Mobile Media API (MMAPI)
Company typeSpecification
IndustrySoftware, Mobile technology
ProductsMultimedia API for Java ME (JSR 135)
ParentJava Community Process
Websitejcp.org/en/jsr/detail?id=135

The Mobile Media API (MMAPI) defines an API specification tailored for the Java ME platform, particularly targeting CDC and CLDC devices such as mobile phones. Depending on how it is implemented, this API allows applications to play and record audio and video, as well as capture still images. The MMAPI was created through the Java Community Process and formalized as JSR 135.

Programming concepts

At the core of the Multimedia Java API are four principal classes within the javax.microedition.media package: Manager, Player, PlayerListener, along with multiple Control interfaces.

Developers working with Java ME primarily utilize the static methods provided by the Manager class, especially createPlayer, which accepts either a URI or an input stream plus an optional MIME type. Common URI schemes supported include:

  • file:
  • resource: (extraction from MIDlet JAR varies by implementation)
  • http:
  • rtsp:
  • capture: (for capturing audio or video)

The createPlayer method returns an instance implementing the Player interface, offering fundamental operations such as starting, stopping, and looping media playback. A PlayerListener can be attached to respond to events like playback initiation, cessation, or completion.

Each Player exposes a getControl method to retrieve specific Control interfaces that provide optional functionalities, which are not universally applicable across all media types. The availability of controls depends on the player implementation; often, the player itself directly implements these control interfaces.

The standard controls defined within the javax.microedition.media.control package include:

Key MMAPI Control Interfaces
Control Interface Purpose
FramePositioningControl Enables access to individual frames within video content.
GUIControl Handles visual presentation for media requiring user interface components.
MetaDataControl Provides retrieval of metadata such as title, author, and copyright information.
MIDIControl Facilitates interaction with device MIDI playback capabilities.
PitchControl Allows adjustment of audio pitch levels.
RateControl Controls the speed at which media is played back.
RecordControl Manages recording functions from capture devices like cameras and microphones.
StopTimeControl Enables setting a predefined stop time during playback.
TempoControl Modifies tempo for audio playback, commonly used with MIDI sequences.
ToneControl Supports playback of monotonic tone patterns.
VideoControl Extends GUIControl to manage video display aspects.
VolumeControl Adjusts audio output volume.

Additional control interfaces are specified in JSR 234 (Advanced Multimedia Supplements).

A portion of JSR 135 is incorporated within JSR 118 (MIDP 2.0).

Player lifecycle

Regardless of media format or protocol in use, a Player instance transitions through a series of defined states during its lifecycle:

Player instance lifecycle states
State Explanation
Unrealized Initial phase where the player has insufficient information to acquire resources necessary for media processing.
Realized The player has gathered essential details and likely obtained most resources; however, some system-dependent components (such as audio or video drivers) may still be pending acquisition.
Prefetched All required resources—including limited or system-specific ones—have been secured. The player is fully prepared to execute its functions.
Started The player is actively processing and rendering media content.
Closed Terminal state indicating that the player’s lifecycle has ended and it must not be reused.


Implementations

Despite efforts within the specification to promote standardization, Java ME implementations exhibit notable variations. These discrepancies are evident in the range of supported controls and the types of URIs recognized. Performance differences are also significant; for instance, when handling HTTP streaming, implementations vary in the timing of when data begins to download. The specification includes realize and prefetch methods designed to prepare media beforehand, with certain implementations allowing streaming playback concurrently.

The Symbian OS platform provides a robust JSR 135 implementation; however, multimedia functionality depends heavily on device capabilities and manufacturer decisions, which can influence features such as recording support.

Uniformity among different implementations is ensured by the mandatory successful completion of the Java Technology Compatibility Kit (TCK), which verifies compliance with supported URI schemes, MIME types, and Controls. It does not, however, cover all optional feature combinations.

Code example

<syntaxhighlight lang="java"> package org.wikipedia;

import javax.microedition.midlet.*; import javax.microedition.media.*;

public class SimplePlayer extends MIDlet {

    protected void destroyApp(boolean unconditional) throws MIDletStateChangeException {}
    protected void pauseApp() {}
    protected void startApp() throws MIDletStateChangeException {
         try {
              String url = "http://upload.wikimedia.org/wikipedia/commons/a/a0/Bass_sample.mid";
              Player player = Manager.createPlayer(url);
              player.start();
         } catch (Exception e) {
              e.printStackTrace();
         }
    }

} </syntaxhighlight>

See also

Bibliography

  • Vikram Goyal, Pro Java ME MMAPI: Mobile Media API for Java Micro Edition, Apress, 1st edition, May 1, 2006, 250 pages, ISBN 1-59059-639-0

External links