final int videoFieldX = (displayWidth - VIDEO_WIDTH) / 2;
final int videoFieldY = (displayHeight - VIDEO_HEIGHT) / 2;
absoluteFieldManager.add(videoField, videoFieldX, videoFieldY);
// Create a ComponentCanvas for overlaying fields on the video
final ComponentCanvas componentCanvas =
new ComponentCanvas(VIDEO_WIDTH + MARGIN, VIDEO_HEIGHT
+ MARGIN);
// Calculate the position of the ComponentCanvas
// and add to the manager.
final int canvasX = (displayWidth - (VIDEO_WIDTH + MARGIN)) / 2;
final int canvasY = (displayHeight - (VIDEO_HEIGHT + MARGIN)) / 2;
absoluteFieldManager.add(componentCanvas, canvasX, canvasY);
// Button for pausing the video
final ButtonField pauseButton =
new ButtonField("Pause", ButtonField.CONSUME_CLICK
| ButtonField.NEVER_DIRTY);
pauseButton.setCommand(new Command(new CommandHandler() {
public void execute(final ReadOnlyCommandMetadata metadata,
final Object object) {
// Pause the video
try {
_player.stop();
} catch (final Exception e) {
NWMDemo.errorDialog(e.toString());
}
}
}));
final Image pauseImage =
ImageFactory.createImage(Bitmap
.getBitmapResource("pause.png"));
pauseButton.setImage(pauseImage);
componentCanvas.add(pauseButton, 0, VIDEO_HEIGHT - 15);
// Button to start/re-start the video
final ButtonField playButton =
new ButtonField("Play", ButtonField.CONSUME_CLICK
| ButtonField.NEVER_DIRTY);
playButton.setCommand(new Command(new CommandHandler() {
public void execute(final ReadOnlyCommandMetadata metadata,
final Object object) {
// Start the video
try {
_player.start();
} catch (final Exception e) {
NWMDemo.errorDialog(e.toString());
}
}
}));
final Image playImage =
ImageFactory.createImage(Bitmap
.getBitmapResource("play.png"));
playButton.setImage(playImage);
componentCanvas
.add(playButton, VIDEO_WIDTH - 80, VIDEO_HEIGHT - 15);
}
}