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.
Constant Value Description BUFFEREMPTY 6 The buffer is completely empty. The media may pause because there is no data in the buffer. BUFFERING should start. BUFFERING 5 Media is currently buffering. EOF 8 The player has reached the end of the media file. ERROR 10 The player gave an error while trying to playback a media file. FORWARD 2 The media is moving forward on a increased speed. INFOLOADED 7 Information about the media has been loaded, including header file information and media data. INIT -1 The player is initializing. PAUSE 1 The media file is paused. PLAY 0 The media file is playing. REWIND 3 The media file is rewinding. STOP 4 The media file is stopped. UNKNOWN 9 The 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:
Name Type Description muted Boolean 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:
Name Type Argument Description time Number Seek to the specified time in seconds.
absolute Boolean optional 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:
Name Type Description idx Number 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:
Name Type Description pls MAF.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:
Name Type Description number Number Number to tune the TV to.
Events
onBufferChanged
Fired when playback controls are pressed.
Properties:
Name Type Description payload Object Properties
Name Type Description bufferPercentage Number Indicates how far buffering is done with a percentage.
playerStatus Number 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:
Name Type Description payload Object Properties
Name Type Description index Number 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:
Name Type Description payload Object Properties
Name Type Description playlist MAF.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:
Name Type Description payload Object Properties
Name Type Description entry MAF.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:
Name Type Description payload Object Properties
Name Type Description current Number Speed rate it currently plays the media on.
previous Number 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:
Name Type Description payload Object Properties
Name Type Description newState Number The state the player just transitioned in.
previousState Number 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:
Name Type Description payload Object Properties
Name Type Description duration Float timeIndex Float onViewportBoundsChanged
Fired when media playback bounds have changed.
Properties:
Name Type Description payload Object Properties
Name Type Description current Object Current size and position of the media playback bounds.
Properties
Name Type Description x Number Horizontal position.
y Number Vertical position
width Number Width of the playback bound.
height Number Height of the playback bound.
previous Object Previous size and position of the media playback bounds.
Properties
Name Type Description x Number Horizontal position.
y Number Vertical position
width Number Width of the playback bound.
height Number Height of the playback bound.