Playing video is similar to playing audio. However, the video player
needs to be told where to display the video. Therefore you get a VideoControl
from
the video player and display it either as a Form
item
or in a Canvas
.
To display video as a Form
item:
InputStream is = getClass().getResourceAsStream("/somefile.3gp"); Player player = Manager.createPlayer(is, "video/3gpp"); player.realize(); VideoControl vc = (VideoControl)player.getControl("VideoControl"); if (vc != null) { Item it = (Item)vc.initDisplayMode(VideoControl.USE_GUI_PRIMITIVE, null); myForm.append(it); p.start(); }
To display video in a Canvas
(for a full example,
see the example MIDlet's source code):
InputStream is = getClass().getResourceAsStream("/somefile.3gp"); Player player = Manager.createPlayer(is, "video/3gpp"); player.realize(); VideoControl vc = (VideoControl)player.getControl("VideoControl"); if (vc != null) { vc.initDisplayMode(VideoControl.USE_DIRECT_VIDEO, myCanvas); vc.setVisible(true); p.start(); }
Note that by default a video control displayed in a Canvas
is
not visible.
If the VideoControl's display mode is set to USE_DIRECT_VIDEO
,
the second parameter of the initDisplayMode
method can
be either a Canvas
or an object created from Canvas
.
In the VideoControl's setDisplaySize
method, the
image will be scaled to fit if the requested display size is different from
the dimensions of the video clip. In Canvas
, VideoControl's setDisplayFullScreen(true)
method
sets the display to the whole Canvas
, not the whole screen.
The values returned by the getDisplayWidth
and getDisplayHeight
methods
are unaffected by this call (that is, they do not afterwards return the width
and height of the full screen).
Note: Video scaling is supported in Series 40 devices from 3rd Edition, Feature Pack 2 onwards.