Java Reference
In-Depth Information
Displaying the Video
Unlike audio, which is played back through the speakers, video will take up some space on the
user interface. MMAPI makes this quite simple. You have two choices:
Display the video on a custom
Canvas
.
•
Display the video as an
Item
within a
Form
.
•
In either case, you must first get hold of a
VideoControl
instance. You do this the same way
you'd get a
VolumeControl
or
ToneControl
from an audio player:
(VideoControl) vidc = (VideoControl) player.getControl("VideoControl");
Once you have this
VideoControl
instance, you can create either your custom
Canvas
class
or a video
Item
for form-based display.
Video on Custom Canvas
If you want to display the video on a custom
Canvas
, you need to derive a class from
Canvas
. Say
that your class is called
VideoCanvas
; the following code in the constructor will position and
display the video:
public VideoCanvas(VideoControl videoControl) {
videoControl.initDisplayMode(
VideoControl.USE_DIRECT_VIDEO, this);
try {
videoControl.setDisplayLocation(5, 5);
videoControl.setDisplaySize(getWidth()- 10, getHeight ()- 10);
}
catch (MediaException ex) {
....
}
videoControl.setVisible(true);
}
Note that you need to pass in the
VideoControl
instance during construction.
The video display is created using the
initDisplayMode()
method, and the mode
VideoControl.USE_DIRECT_VIDEO
indicates to the
VideoControl
that you are working
within a
Canvas
subclass. In this case, the video display takes up the entire
VideoCanvas
,
with a 5-pixel border on all four sides.
Video on an Item Within a Form
Using an
Item
to display the video allows you to mix the video with other
Item
s on a
Form
. The
VideoMIDlet
code in Listing 16-5 uses this approach. You can obtain an
Item
instance by calling
the
initDisplayMode()
method using a mode of
VideoControl.USE_GUI_PRIMITIVE
:
Search WWH ::
Custom Search