MAF.mediaplayer Singleton

MAF.mediaplayer class defines the interactions available inside a app on the mediaplayer.

MAF.mediaplayer()

Example

(function (event) {
   log(event.payload);
}).subscribeTo(MAF.mediaplayer, 'onStateChange');

var playlist = new MAF.media.Playlist();
playlist.addEntryByURL('http://my.url.com/video.mp4');
MAF.mediaplayer.playlist.set(playlist);
MAF.mediaplayer.playlist.start();

Members

constants.states :Object staticreadonly

Here are the possible enumeration constants for the player states.

ConstantValueDescription
BUFFEREMPTY6The buffer is completely empty. The media may pause because there is no data in the buffer. BUFFERING should start.
BUFFERING5Media is currently buffering.
EOF8The player has reached the end of the media file.
ERROR10The player gave an error while trying to playback a media file.
FORWARD2The media is moving forward on a increased speed.
INFOLOADED7Information about the media has been loaded, including header file information and media data.
INIT-1The player is initializing.
PAUSE1The media file is paused.
PLAY0The media file is playing.
REWIND3The media file is rewinding.
STOP4The media file is stopped.
UNKNOWN9The player triggered a state unknown to the MAF.mediaplayer

player.currentMediaDuration :Float staticreadonly

Duration of the currently active media on the player.

player.currentPlayerState :Number staticreadonly

State of the player it is currently in.

player.currentSpeed :Number staticreadonly

Playback speed of the currently active media on the player.

player.currentTimeIndex :Float staticreadonly

Time index of the currently active media on the player.

isPlaylistEntryActive :Boolean|MAF.media.PlaylistEntry staticreadonly

Indicates if the current playlist entry is in a active state. This can can be any of these states: PLAY, PAUSE, FORWARD, REWIND, BUFFERING, INFOLOADED

isSidebarHidden :Boolean staticreadonly

Indicates if there currently is any kind of app view visible.

isTVActive :Boolean staticreadonly

Indicates if the TV is active as media playback. This also means there is no playlist entry.

Methods

control.forward() static

This will forward current media. If the OEM supports faster speeds calling this method multiple times will increment the forward speed.

control.hide() static

This will hide the media.

control.mute(muted) static

The will mute the audio of the media.

Parameters:

NameTypeDescription
mutedBoolean

Define true to mute the media false to unmute.

control.pause() static

Pause the playback of the currently playing media.

control.play() static

Continue the playback of the media that is paused. Only call this method when the media is paused.

control.rewind() static

This will rewind current media. If the OEM supports faster speeds calling this method multiple times will increment the rewind speed.

control.seek(time, absolute) static

Move the media position to the defined time.

Parameters:

NameTypeArgumentDescription
timeNumber

Seek to the specified time in seconds.

absoluteBooleanoptional 

Default this method will use the time parameter to seek relative from the current position in the media. Use true to seek to a absolute position.

control.show() static

This will show the media.

control.stop() static

Stop the playback of the currently playing media.

init() static

Initializes the mediaplayer. This allows the use of playback and/or event listeners.

playlist.get() → {MAF.media.Playlist} static

Returns:

Currently active playlist.

playlist.loadEntry(idx) static

Load the entry in the playlist defined bu the supplied idx parameter.

Parameters:

NameTypeDescription
idxNumber

Index defining the entry in the playlist to load.

playlist.nextEntry() static

Go to the next entry in the playlist.

playlist.previousEntry() static

Go to the previous entry in the playlist.

playlist.set(pls) static

Set a playlist on the mediaplayer.

Parameters:

NameTypeDescription
plsMAF.media.Playlist

The playlist to set on the mediaplayer.

Example

MAF.mediaplayer.playlist.set((new MAF.media.Playlist()).addEntry(new MAF.media.PlaylistEntry(config)));

playlist.start() static

This will try to start the playback of the playlist on the mediaplayer. A playlist needs to be set on the mediaplayer before calling this with MAF.mediaplayer.playlist.set()

getCurrentChannel() → {Object}

This will give information about a channel the tv currently is tuned to.

Returns:

TVChannel Containing:

  • name - Channel name
  • description - Description of the channel
  • number - Number of the channel
  • entitled - Returns if the user is entitled for the channel (boolean)

getCurrentProgram() → {Object}

This will give information about a current program the tv is currently tuned to.

Returns:

TVProgram Containing:

  • title - Title of the program
  • description - Description of the program
  • startTime - Time the program started
  • duration - Duration of the program in seconds.
  • ageRating - What agesrating the program has been rated for.

getViewportBounds() → {Object}

Get the size and position of the players viewport.

Returns:

Object containing:

  • x - Horizontal position.
  • y - Vertical position.
  • width - Width of the players viewport.
  • height - Height of the players viewport.

setChannelByNumber(number)

Set the channel the TV should try and tune to.

Parameters:

NameTypeDescription
numberNumber

Number to tune the TV to.

setViewportBounds(x, y, width, height)

Set the size and position of the players viewport.

Parameters:

NameTypeDescription
xNumber

Horizontal position.

yNumber

Vertical position.

widthNumber

Width of the players viewport.

heightNumber

Height of the players viewport.

Events

onBufferChanged

Fired when playback controls are pressed.

Properties:
NameTypeDescription
payloadObject
Properties
NameTypeDescription
bufferPercentageNumber

Indicates how far buffering is done with a percentage.

playerStatusNumber

Indicates what state the player is in. Can be matched against MAF.mediaplayer.constants.states

onChannelChange

Fired when the channel on the TV has changed.

onFastForwardRemoteKeyPress

Fired when the fast forward key was pressed on the remote control.

onLoadNextPlaylistEntry

Fired when the next playlist entry is called.

onLoadPlaylistEntry

Fired when a playlist entry has been selected for playback.

Properties:
NameTypeDescription
payloadObject
Properties
NameTypeDescription
indexNumber

Playlist index to be loaded.

onLoadPreviousPlaylistEntry

Fired when the previous playlist entry is called to be played.

onPauseRemoteKeyPress

Fired when pause key was pressed on the remote control.

onPlaylistChange

Fired when the playlist on the player has changed. event.preventDefault() will prevent the changes to be applied.

Properties:
NameTypeDescription
payloadObject
Properties
NameTypeDescription
playlistMAF.media.Playlist

The playlist that will be applied to the mediaplayer.

onPlaylistEnd

Fired when the end of the playlist has been reached.

onPlaylistRepeat

Fired when the player is repeating the playback of a playlist.

onPlayPlaylistEntry

Fired when playback of a new playlist entry starts.

onPlayRemoteKeyPress

Fired when the play key was pressed on the remote control.

onProcessPlaylistEntry

Fired when the mediaplayer has selected a new playlist entry for playback.

Properties:
NameTypeDescription
payloadObject
Properties
NameTypeDescription
entryMAF.media.PlaylistEntry

The entry to be used for playback.

onRemoteKeyPress

Fired when a key was pressed on the remote control. Can be used to handle all keys with a single handler if you call event.preventDefault()

onRewindRemoteKeyPress

Fired when the rewind key was pressed on the remote control.

onSetPlaybackSpeed

Fired when the playback speed has changed.

Properties:
NameTypeDescription
payloadObject
Properties
NameTypeDescription
currentNumber

Speed rate it currently plays the media on.

previousNumber

Speed rate it previously was playing the media on.

onStartPlaylist

Fired when a playlist starts playback. Usually when MAF.mediaplayer.playlist.start() is called.

onStateChange

Fired each time media gets into a new state. You can match the states in the payload against MAF.mediaplayer.constants.states

Properties:
NameTypeDescription
payloadObject
Properties
NameTypeDescription
newStateNumber

The state the player just transitioned in.

previousStateNumber

The state the player was in.

Example

var onStateChange = function (event) {
   var state = event && event.payload && event.payload.newState,
       states = MAF.mediaplayer.constants.states;
   switch (state) {
      case states.PLAY:
         //Player is in the playback state.
         break;
      case states.PAUSE:
      	//Player is in the pause state.
      	break;
   }
}
onStateChange.subscribeTo(MAF.mediaplayer, 'onStateChange');

onStopRemoteKeyPress

Fired when the stop key is pressed on the remote control.

onTimeIndexChanged

Fired when the current playback position changed.

Properties:
NameTypeDescription
payloadObject
Properties
NameTypeDescription
durationFloat
timeIndexFloat

onViewportBoundsChanged

Fired when media playback bounds have changed.

Properties:
NameTypeDescription
payloadObject
Properties
NameTypeDescription
currentObject

Current size and position of the media playback bounds.

Properties
NameTypeDescription
xNumber

Horizontal position.

yNumber

Vertical position

widthNumber

Width of the playback bound.

heightNumber

Height of the playback bound.

previousObject

Previous size and position of the media playback bounds.

Properties
NameTypeDescription
xNumber

Horizontal position.

yNumber

Vertical position

widthNumber

Width of the playback bound.

heightNumber

Height of the playback bound.