Packageqnx.ui.media
Classpublic class MediaControl
InheritanceMediaControl Inheritance UIComponent Inheritance flash.display.MovieClip

The 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:

View the examples

See also

MediaControlOption
MediaControlProperty
MediaControlState


Public Properties
 PropertyDefined By
 Inheritedcontainment : String
Gets or sets a property that determines how a component is contained within a parent container.
UIComponent
 Inheritedsize : Number
Gets or sets the size for this component (as a percentage of the container's size, or in pixels).
UIComponent
 InheritedsizeMode : String
Gets or sets the size mode for this component.
UIComponent
 InheritedsizeUnit : String
Gets or sets the unit of measure for the size property.
UIComponent
Public Methods
 MethodDefined By
  
Creates a MediaControl instance.
MediaControl
 Inherited
destroy():void
Call this method when you want to have your object collected by the garbage collector.
UIComponent
 Inherited
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
 Inherited
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
 Inherited
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
 Inherited
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
Protected Methods
 MethodDefined By
 Inherited
callLater(method:Function):void
Calls the specified method on the next frame or the next render, which ever happens first.
UIComponent
 Inherited
createInstance(linkage:Object):DisplayObject
Calling this method will attempt to create a DisplayObject instance based on the value of the linkage parameter.
UIComponent
 Inherited
draw():void
Called every time you set the width and height of the component.
UIComponent
 Inherited
isInvalid(property:String, ... properties):Boolean
Checks to see if the property is invalid and returns true if it is.
UIComponent
 Inherited
onAdded():void
Called when the instance is added to the stage.
UIComponent
 Inherited
onRemoved():void
Called when the instance is removed from the stage.
UIComponent
 Inherited
setEnabled(val:Boolean):void
Called when the enabled property changes.
UIComponent
 Inherited
validate(property:String):void
Lets the component know that the specified property has been validated.
UIComponent
Events
 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
Constructor Detail
MediaControl()Constructor
public function MediaControl()

Creates a MediaControl instance.

Method Detail
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.

Returns
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.

Returns
Boolean — Returns true if the option is enabled, otherwise false.

See also

getProperty()method 
public function getProperty(prop:String):Object

Gets the current value of the specified property. The expected return value types are:

PropertyReturn 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.

Returns
Object

See also

getState()method 
public function getState():String

Gets the state of the control.

One of the following values will be returned:

Returns
String

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:

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:

Parameters

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:
PropertyExpected value
MediaControlProperty.DURATION The duration of the media in milliseconds
MediaControlProperty.POSITION The duration of the media in milliseconds
MediaControlProperty.FULLSCREEN true if the media is in fullscreen mode or false if it is not.
MediaControlProperty.VOLUME An int value ranging between 0 and 100.
 
value:Object — The value to set (see table above).

See also

setState()method 
public function setState(state:String):void

Sets the state of the control.

This method expects one of the following values:

Parameters

state:String — The state to set.

See also

Event Detail
optionClicked Event
Event Object Type: qnx.ui.events.MediaControlEvent
MediaControlEvent.type property = qnx.ui.events.MediaControlEvent.OPTION_CLICK

Dispatched 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  
Event Object Type: qnx.ui.events.MediaControlEvent
MediaControlEvent.type property = qnx.ui.events.MediaControlEvent.PROPERTY_CHANGE

Dispatched when a property has changed through user interaction.

The following cases will cause this event to be dispatched:

See also

stateChange Event  
Event Object Type: qnx.ui.events.MediaControlEvent
MediaControlEvent.type property = qnx.ui.events.MediaControlEvent.STATE_CHANGE

Dispatched 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

Examples

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;
            }
        }
        
    }
    
    
}