Java Reference
In-Depth Information
// Creates a VideoPlayer and gets an associated VideoControl
public void createPlayer() throws ApplicationException
{
try
{
player = Manager.createPlayer("capture://video");
player.realize();
// Sets VideoControl to the current display.
videoControl = (VideoControl)(player.getControl("VideoControl"));
if (videoControl == null)
{
discardPlayer();
}
else
{
videoControl.initDisplayMode(VideoControl.USE_DIRECT_VIDEO, canvas);
int cWidth = Canvas.getWidth();
int cHeight = Canvas.getHeight();
int dWidth = 160;
int dHeight = 120;
videoControl.setDisplaySize(dWidth, dHeight);
videoControl.setDisplayLocation((cWidth - dWidth)/2,
(cHeight - dHeight)/2);
By setting the canvas to be the current one in the display, we can use
it as a viewfinder for the camera. When we are ready to take a picture,
we simply call
getSnapshot(null)
on the
VideoControl
:
public byte[] takeSnapshot() throws ApplicationException
{
byte[] pngImage = null;
if (videoControl == null)
{
throw new ApplicationException
("Unable to capture photo: VideoControl null");
}
try
{
pngImage = videoControl.getSnapshot(null);
}
catch(MediaException me)
{
throw new ApplicationException("Unable to capture photo",me);
}
return pngImage;
}
It should be noted that, if a security policy is in operation, user
permission may be requested through an intermediate dialog, which may
interfere with the photography!
2.9.7 Generating Tones
MMAPI also supports tone generation. Generating a single tone is simply
achieved using the following method of the
Manager
class:
public static void playTone(int note, int duration, int volume)
throws MediaException