Adding Controls to a Simple Mobile Video Player

By Baechul Kim, February 2nd, 2009

The SimpleVideoPlayerMobile sample is a mobile version of SimpleVideoPlayer. You could use the JavaFX Media Component for mobile in the com.sun.fxmediacomponent package to build a video player.

SimpleVideoPlayerMobile

Understanding the Code

The JavaFX Media Component for Mobile is a visual component that provides the standard video player controls. It has a play or pause button, a slider to play forward or backward, and a time indicator. Using the JavaFX Media Component for Mobile couldn't be any simpler. Just create an instance of the component with a link to your video, set a few variables, then put it in a Stage, as shown in Figure 1.

Source Code
package simplevideoplayermobile;

import javafx.stage.Stage;
import javafx.scene.Scene;

import com.sun.fxmediacomponent.*;

var scene:Scene;
var width:Number = 320;
var height:Number = 240;

var mediaComponent:MediaComponent = MediaComponent {
    mediaViewWidth: width 
    mediaViewHeight: height

    mediaSourceURL: "http://sun.edgeboss.net/download/sun/09q2/09b01828/09b01828_11.mov"
}

scene = Scene {
  content: mediaComponent
}

Stage {
    title: "Simple Video Player Mobile"
    width: 240
    height: 320
    scene: scene
    resizable: false
}

Figure 1: Using the MediaComponent

The previous example code requires you to install QuickTime, as the MOV file is used. Note that the emulator can be run only in a supported windows machine.

You can rotate the emulator to view the video in landscape mode. To rotate the emulator from the emulator window, choose View > Orientation> 90.

English
日本語
한국어
简体中文
Português do Brasil