Java Reference
In-Depth Information
VideoCanvas renders the video playback and the other classes fulfill
very similar roles to their equivalents in the Audio Player MIDlet.
The resource file name is tested to ascertain its format (MPEG for the
WTK emulator and 3GPP for real phones) and the appropriate MIME
type. A new thread is then launched to perform the essential initialization
required to play the video content. The run() method, mandated by the
Runnable interface, contains the initialization of the Player :
public void run() {
try {
InputStream in = getClass().getResourceAsStream("/"+ resource);
player = Manager.createPlayer(in, mimeType);
player.addPlayerListener(controller);
player.realize();
player.prefetch();
videoControl = (VideoControl)player.getControl("VideoControl");
if (videoControl != null) {
videoControl.initDisplayMode(
videoControl.USE_DIRECT_VIDEO, canvas);
int cHeight = canvas.getHeight();
int cWidth = canvas.getWidth();
videoControl.setDisplaySize(cWidth, cHeight);
videoControl.setVisible(true);
startPlayer();
} else {
controller.showAlert("Error!", "Unable to get Video Control");
closePlayer();
}
} catch (IOException ioe) {
controller.showAlert("Unable to access resource", ioe.getMessage());
closePlayer();
} catch (MediaException me) {
controller.showAlert("Unable to create player",
me.getMessage());
closePlayer();
}
}
An InputStream is obtained from the resource file and is used to
create the Player instance. A PlayerListener (the controller) is reg-
istered with the Player in order to receive callbacks. The prefetch()
and realize() methods are then called on the Player instance.
Once the player is in the PREFETCHED state, we are ready to render
the video content. First we must obtain a VideoControl by calling
getControl() on the Player and casting it down appropriately.
The initDisplayMode() method is used to initialize the video
mode that determines how the video is displayed. This method takes
an integer mode value as its first argument with one of two predefined
values: USE GUI PRIMITIVE or USE DIRECT VIDEO. In the case of MIDP
Search WWH ::




Custom Search