Using video in eSWT

You can use the MMAPI to play back video content or display the camera viewfinder on an eSWT Control.

Using the MMAPI with eSWT is supported since S60 3rd Edition, Feature Pack 2.

Creating a video player

To display video content in an eSWT UI:

  1. Create a Player for the video content. The following code snippet creates a Player for playing back the video file http://mymachine/abc.mpg.

    Player player = Manager.createPlayer("http://mymachine/abc.mpg");
    player.realize();

    For further instructions, see sections Playing video and Recording sound and video.

    For information about the video content types supported by the Symbian platform, see section Content types.

  2. Create the eSWT Control on which the video content is displayed.

    // Create a MMAPI VideoControl object for controlling the Player
    VideoControl videoControl = (VideoControl)player.getControl("VideoControl");
    
    // Create an eSWT Control for displaying the Player
    Control vControl = (Control)videoControl.initDisplayMode(VideoControl.USE_GUI_PRIMITIVE, "org.eclipse.swt.widgets.Control");
  3. Set the parent for the eSWT Control. The following code snippet uses a Shell as the parent.

    vControl.setParent(shell);
  4. Start the playback.

    player.start();
  5. Create the UI controls for the Player. For instructions on creating an eSWT UI, see section Using eSWT.

Example eSWT video player

The following code creates a simple eSWT MIDlet that plays back a video file. The MIDlet does not include any playback controls for the video file. The MIDlet uses the eSWT MIDlet starter to create the eSWT UI thread and manage the MIDlet lifecycle.

import javax.microedition.media.*;
import javax.microedition.media.control.*;
import java.io.InputStream;
import java.io.IOException;
import org.eclipse.ercp.swt.mobile.Command;
import org.eclipse.swt.events.*;
import org.eclipse.swt.widgets.*;

public class SimpleVideoPlayerMIDlet
    extends SWTMIDlet
    implements SelectionListener, PaintListener {

    // eSWT Shell created on SWTMIDlet.display
    private Shell shell;

    // MMAPI video Player
    private Player player;

    // MMAPI VideoControl for the MMAPI video Player
    private VideoControl videoControl;

    // eSWT Control for the MMAPI video Player
    private org.eclipse.swt.widgets.Control vControl;

    // Create the eSWT UI in the UI thread from SWTMIDlet
    public void runUI(Display display) {

        // Create the Shell on the Display
        shell = new Shell(display);
        shell.open();

        Command exitCommand = new Command(shell, Command.EXIT, 0);
        exitCommand.setText("Exit");
        exitCommand.addSelectionListener(this);

        // Create the video Player and display it on the Shell
        try {
            InputStream in = getClass().getResourceAsStream("video.3gp");
            player = Manager.createPlayer(in, "video/3gpp");
            player.realize();
            player.prefetch();
            videoControl = (VideoControl)player.getControl("VideoControl");
            vControl = (org.eclipse.swt.widgets.Control)videoControl.initDisplayMode(VideoControl.USE_GUI_PRIMITIVE, "org.eclipse.swt.widgets.Control");
            vControl.setParent(shell);
            player.start();
        } catch (IOException e) {
        } catch (MediaException e) {
        }

    }

    public void widgetDefaultSelected(SelectionEvent e) {
    }

    public void widgetSelected(SelectionEvent e) {
        // Exit command selected, so exit the event loop
        exit();
    }

    public void paintControl(PaintEvent e) {
    }

}

For an example eSWT MIDlet that uses the MMAPI to take pictures using the phone's camera, see article Using eSWT and MMAPI together to take a picture in Java ME in the Nokia Developer Wiki.