Position a Video within a Screen

by Retired on ‎08-13-2010 02:24 PM - edited on ‎09-16-2010 03:26 PM by Retired (3,385 Views)

This article demonstrates how you can position a video within an Ui Application.


The key ideas to note:





The MainScreen layout has to be extended to its maximum allowed width and height in order to place the Video object at a desired position on the screen.

MainScreen myScreen = new MainScreen(MainScreen.USE_ALL_WIDTH|MainScreen.USE_ALL_HEIGHT);


In customizing the layout manager and overriding the sublayout method, you are effectively instructing each child field where to be laid out within in its manager.

public void sublayout(int height, int width);


The VideoControl object is converted into a Field and its size adjusted for allowing the Manager to control its position in layout.

Field videoField = (Field) videoControl.initDisplayMode(VideoControl.USE_GUI_PRIMITIVE,

videoControl.setDisplaySize(150, 150);




import javax.microedition.media.Manager;
import javax.microedition.media.Player;
import javax.microedition.media.control.VideoControl;

import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.component.Dialog;
import net.rim.device.api.ui.container.MainScreen;

* How to implement a Video in a Windowed View within an
* Ui Application
* PlayVideo.java main class

public final class PlayVideo extends UiApplication

public static void main(String[] args)
PlayVideo theApp = new PlayVideo();

public PlayVideo()
// Layout Manager is created
LayoutManager myManager = new LayoutManager();

// The mainscreen width and height is extended in
// order to allow the layout manager access to the
// entire device screen
MainScreen myScreen = new MainScreen(
try {
// The media file is imported.
String fileName = "sample.mp4";
Player player = Manager.createPlayer("file:///SDCard/" + fileName);

//Create a new VideoControl.
VideoControl videoControl = (VideoControl) player.getControl("VideoControl");
videoControl = (VideoControl)player.getControl("VideoControl");

// Setting the VideoControl to primitive and casting it as a field
// in order to give the manager access to manipulate its position
Field videoField = (Field) videoControl.initDisplayMode(
// Setting the size of the video.
videoControl.setDisplaySize(150, 150);
// Adding the Manager to the screen
// Adding the Video Object field into the Manager with
// its desired position set in sublayout of the LayoutManager Class
} catch (Exception e) {
Dialog.alert("Error in Positioning Video");



import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.Manager;

* A custom layout manager is created for the purpose of
* overloading the sublayout method.
* LayoutManager.java

class LayoutManager extends Manager {
public LayoutManager() {
//construct a manager with vertical scrolling
//overwrite the nextFocus method for custom navigation
protected void sublayout(int width, int height) {
Field field;
//get total number of fields within this manager
int numberOfFields = getFieldCount();
// A vertical spacing of 50units is created
int y = 50;

// Laying out every field in the manager evenly
for (int i = 0;i < numberOfFields;i++) {
field = getField(i); //get the field
setPositionChild(field,100,y); //set the position for the field
layoutChild(field, width, height); //lay out the field
y +=50;
setExtent(width, height);



See the following learning resources for more information on the APIs used in this article: