| Package | qnx.ui.media |
| Class | public class MediaControl |
| Inheritance | MediaControl UIComponent flash.display.MovieClip |
MediaControl class provides a set of controls that can be used to control media, such as video and audio.
The control itself does not control the media. Instead, it broadcasts events as the user interacts with the controls. You can customize the control by setting options to hide or show interface features.
The following image shows a MediaControl instance with all UI options enabled:
See also
| Method | Defined By | ||
|---|---|---|---|
Creates a MediaControl instance. | MediaControl | ||
![]() | destroy():void
Call this method when you want to have your object collected by the garbage collector. | UIComponent | |
![]() | drawNow():void
Calls the draw() method. | UIComponent | |
getOption(option:String):Boolean
Returns a Boolean indicating whether or not the option is shown. | MediaControl | ||
getOptionEnabled(option:String):Boolean
Returns a Boolean indicating whether or not the option is enabled. | MediaControl | ||
getProperty(prop:String):Object
Gets the current value of the specified property. | MediaControl | ||
getState():String
Gets the state of the control. | MediaControl | ||
![]() | invalidate(property:String, invalidateNow:Boolean = false):void
Marks the property as invalid and the draw() method is called on the next frame or the next render, whichever comes first. | UIComponent | |
setOption(option:String, value:Boolean):void
Allows you to hide and show features of the MediaControl class. | MediaControl | ||
setOptionEnabled(option:String, value:Boolean):void
Allows you to enable and disable UI control items of the MediaControl class. | MediaControl | ||
![]() | setPosition(x:Number, y:Number):void
Sets the x and y position of the component. | UIComponent | |
setProperty(prop:String, value:Object):void
Sets a property to the specified value in the MediaControl component
In the following listing, the volume property is set to 80 and the fullscreen mode property
is set to true:
controls.setProperty( MediaControlProperty.VOLUME, 80 );
controls.setProperty( MediaControlProperty.FULLSCREEN, true );
| MediaControl | ||
![]() | setSize(w:Number, h:Number):void
Sets the width and height of the component. | UIComponent | |
setState(state:String):void
Sets the state of the control. | MediaControl | ||
| Event | Summary | Defined By | ||
|---|---|---|---|---|
| Dispatched when certain elements in the control are touched by the user. | MediaControl | |||
| Dispatched when a property has changed through user interaction. | MediaControl | |||
| Dispatched when the state of the media must change based on user interaction with the controls. | MediaControl | |||
| MediaControl | () | Constructor |
public function MediaControl()
Creates a MediaControl instance.
| getOption | () | method |
public function getOption(option:String):Boolean
Returns a Boolean indicating whether or not the option is shown.
Parameters
option:String — The option to retrieve.
|
Boolean — Returns true if the option is shown, otherwise false.
|
See also
| getOptionEnabled | () | method |
public function getOptionEnabled(option:String):Boolean
Returns a Boolean indicating whether or not the option is enabled.
Parameters
option:String — The option to retrieve.
|
Boolean — Returns true if the option is enabled, otherwise false.
|
See also
| getProperty | () | method |
public function getProperty(prop:String):ObjectGets the current value of the specified property. The expected return value types are:
| Property | Return value |
|---|---|
MediaControlProperty.DURATION
| int |
MediaControlProperty.POSITION
| int |
MediaControlProperty.FULLSCREEN
| Boolean |
MediaControlProperty.VOLUME
| Number |
MediaControlProperty.STATE
| String |
Parameters
prop:String — The property for which to return the current value.
|
Object |
See also
| getState | () | method |
public function getState():StringGets the state of the control.
One of the following values will be returned:
MediaControlState.PLAYMediaControlState.PAUSEMediaControlState.STOPMediaControlState.SEEK_STARTMediaControlState.SEEK_ENDString |
See also
| setOption | () | method |
public function setOption(option:String, value:Boolean):void
Allows you to hide and show features of the MediaControl class.
By default all items are hidden.
In the following listing, the play, next, and previous buttons are added to the control:
controls.setOption( MediaControlOption.PLAY_PAUSE, true );
controls.setOption( MediaControlOption.NEXT, true );
controls.setOption( MediaControlOption.PREVIOUS, true );
Valid values for the option parameter are:
MediaControlOption.VOLUMEMediaControlOption.FULLSCREENMediaControlOption.NEXTMediaControlOption.PREVIOUSMediaControlOption.PLAY_PAUSEMediaControlOption.SEEKBARMediaControlOption.STOPMediaControlOption.DURATIONMediaControlOption.POSITIONMediaControlOption.BACKGROUND
The MediaControlOption.SEEKBAR option will be disabled if MediaControlProperty.DURATION property
has not been set using the setProperty method.
Parameters
option:String — The option to show or hide.
| |
value:Boolean — When set to true the option is shown. When set to false the option is hidden.
|
See also
| setOptionEnabled | () | method |
public function setOptionEnabled(option:String, value:Boolean):void
Allows you to enable and disable UI control items of the MediaControl class.
By default all items are enabled.
Valid values for the option parameter are:
MediaControlOption.VOLUMEMediaControlOption.FULLSCREENMediaControlOption.NEXTMediaControlOption.PREVIOUSMediaControlOption.PLAY_PAUSEMediaControlOption.SEEKBARMediaControlOption.STOPParameters
option:String — The option to enable or disable.
| |
value:Boolean — When set to true the option is enabled. When set to false the option is disabled.
|
See also
| setProperty | () | method |
public function setProperty(prop:String, value:Object):void
Sets a property to the specified value in the MediaControl component
In the following listing, the volume property is set to 80 and the fullscreen mode property
is set to true:
controls.setProperty( MediaControlProperty.VOLUME, 80 );
controls.setProperty( MediaControlProperty.FULLSCREEN, true );
Parameters
prop:String — The property for which to set a value. Valid properties and values:
| |||||||||||
value:Object — The value to set (see table above).
|
See also
| setState | () | method |
public function setState(state:String):voidSets the state of the control.
This method expects one of the following values:
MediaControlState.PLAYMediaControlState.PAUSEMediaControlState.STOPParameters
state:String — The state to set.
|
See also
| optionClicked | Event |
qnx.ui.events.MediaControlEventqnx.ui.events.MediaControlEvent.OPTION_CLICKDispatched when certain elements in the control are touched by the user.
The following cases will cause this event to be dispatched:
See also
| propertyChange | Event |
qnx.ui.events.MediaControlEventqnx.ui.events.MediaControlEvent.PROPERTY_CHANGEDispatched when a property has changed through user interaction.
The following cases will cause this event to be dispatched:
See also
| stateChange | Event |
qnx.ui.events.MediaControlEventqnx.ui.events.MediaControlEvent.STATE_CHANGEDispatched when the state of the media must change based on user interaction with the controls.
The following cases will cause this event to be dispatched:
See also
The following sample application is included to describe the interaction between the MediaControl class and the
MediaPlayer class. The application launches a movie. The MediaControl class provides the basic UI, while the MediaPlayer
class provides
the rendering. In the example below, a URL to a local movie file is passed into the MediaPlayer instance. The MediaPlayer
and MediaControl communicate state and property changes using events.
This sample assumes that the media file permissions are set properly, and that the media file is executable.
In order to run this sample application, you must set the access_shared permission capability for your application. See the BlackBerry Tablet OS Developer's
Guide for more information.
package
{
import flash.display.Sprite;
import flash.filesystem.File;
import qnx.events.MediaPlayerEvent;
import qnx.media.MediaPlayer;
import qnx.media.VideoDisplay;
import qnx.ui.events.MediaControlEvent;
import qnx.ui.media.
[SWF(width='1024', height='600', backgroundColor='#FFFFFF', frameRate='30')]
public class MediaPlayerSample extends Sprite
{
private var _myPlayer:MediaPlayer;
private var _myVD:VideoDisplay;
private var _myMediaControl:MediaControl;
public function MediaPlayerSample()
{
initializeUI();
initializePlayer();
}
private function initializePlayer():void
{
_myVD = new VideoDisplay;
_myVD.setPosition(1024/2 - 800/2, 600/2 - 480/2);
_myVD.setSize(800, 480);
_myVD.backgroundColor = 0x000000;
addChild(_myVD);
_myPlayer = new MediaPlayer();
_myPlayer.addEventListener(MediaPlayerEvent.INFO_CHANGE, infoChange);
var file:File = File.userDirectory.resolvePath("shared/videos/PlayBook HiDef Demo.mp4");
_myPlayer.url = file.nativePath;
_myPlayer.videoDisplay = _myVD;
}
private function initializeUI():void
{
_myMediaControl = new MediaControl();
_myMediaControl.width = 900;
_myMediaControl.x = Math.round((stage.stageWidth - _myMediaControl.width) / 2);
_myMediaControl.y = stage.stageHeight - _myMediaControl.height;
_myMediaControl.setOption( MediaControlOption.VOLUME, true );
_myMediaControl.setOption( MediaControlOption.PLAY_PAUSE, true );
_myMediaControl.setOption( MediaControlOption.NEXT, true );
_myMediaControl.setOption( MediaControlOption.PREVIOUS, true );
_myMediaControl.setOption( MediaControlOption.STOP, true );
_myMediaControl.setOption( MediaControlOption.SEEKBAR, true );
_myMediaControl.setOption( MediaControlOption.DURATION, true );
_myMediaControl.setOption( MediaControlOption.POSITION, true );
_myMediaControl.setOption( MediaControlOption.BACKGROUND, true);
_myMediaControl.setProperty( MediaControlProperty.VOLUME, 80 );
_myMediaControl.addEventListener( MediaControlEvent.STATE_CHANGE, mediaControlStateChange );
_myMediaControl.addEventListener( MediaControlEvent.PROPERTY_CHANGE, mediaControlPropChange );
addChild(_myMediaControl);
}
private function infoChange(event:MediaPlayerEvent):void {
if (event.what.position) {
_myMediaControl.setProperty(MediaControlProperty.POSITION, _myPlayer.position);
}
if (event.what.duration) {
_myMediaControl.setProperty(MediaControlProperty.DURATION, _myPlayer.duration);
}
if (event.what.state) {
_myMediaControl.setState(_myPlayer.isPlaying ? MediaControlState.PLAY : MediaControlState.PAUSE);
}
}
private function mediaControlStateChange(mediaControlEvent:MediaControlEvent):void
{
var state:String = _myMediaControl.getState();
switch( state )
{
case MediaControlState.PLAY:
if (!_myPlayer.isPlaying)
{
_myPlayer.play();
}
else
{
_myPlayer.speed = 1000;
}
break;
case MediaControlState.PAUSE:
_myPlayer.pause();
break;
case MediaControlState.STOP:
_myPlayer.stop();
break;
case MediaControlState.SEEK_START:
_myPlayer.pause();
break;
case MediaControlState.SEEK_END:
_myPlayer.play();
break;
default:
break;
}
}
private function mediaControlPropChange(event:MediaControlEvent):void {
switch (event.property) {
case MediaControlProperty.POSITION:
{
_myPlayer.seek(uint( _myMediaControl.getProperty(MediaControlProperty.POSITION)));
}
break;
case MediaControlProperty.DURATION:
break;
case MediaControlProperty.FULLSCREEN:
break;
case MediaControlProperty.VOLUME:
break;
default:
break;
}
}
}
}