Media player class. Use this for instantiating a player, attaching it to the DOM, and managing playback.
Constructor
new MediaPlayer(containerId) → {MediaPlayer}
Constructs a new MediaPlayer
instance.
Parameters:
-
containerId
( string )The id of the DOM container element for the player.
Members
advertisingIdentifier :string
A unique advertising-related identifier to assign to the player. This will replace the "%PPID%" VAST macro in tracking URLs defined in VAST tags.
- Default Value:
-
-
''
-
controllerRegistry :ControllerRegistry
Controller registry. Use this to register custom overlays with the player.
Example
player.controllerRegistry.registerOverlayController(CustomOverlayController, 'customc');
currentUnit :MediaUnit|MediaEvent
Current media unit or event being rendered.
hlsHeaders :Object
Additional HTTP headers to attach to HLS media requests.
Example
player.hlsHeaders = {
'X-USES-VEEPLAY': 'true',
'X-TEST-HEADER': 'value',
}
(readonly) id :string
A unique identifier assigned by the system.
mediaUnits :Array.<(MediaUnit|MediaEvent)>
Current upcoming playlist of media units or events to render.
preferGoogleIma :boolean
Use Google's IMA SDK instead of the internal VAST support. Include the official IMA JS library when setting this to true.
- Default Value:
-
-
false
-
Methods
.addEvents(events)
Dynamically insert an array of MediaEvent objects into the current unit
Parameters:
-
events
( Array.<MediaEvent> )Events to insert.
.addOverlays(overlays)
Dynamically insert an array of overlays into the current unit.
Parameters:
-
overlays
( Array.<MediaOverlay> )Overlays to insert.
.audioTracks()
Return the list of AudioTrack objects associated with the current video.
.currentPlaybackTime() → {number}
Return the current playback position.
.duration() → {number}
Retrieve the duration of the currently playing stream.
.enterFullscreen()
Switch to fullscreen mode.
.exitFullscreen()
Switch to inline mode.
.getEventTracker() → {EventTracker}
Get an event tracker manager object. Use this to subscribe to player notifications.
- See:
Example
const tracker = player.getEventTracker();
tracker.emitter.on(NOTIFICATIONS.UNIT_FINISHED, ({ reason, unit }) => {
console.log(`Unit ${unit.url} finished with reason ${reason}`);
if (reason === FINISH_REASON.USER_EXITED) {
console.log('User exited');
}
});
.getMute() → {boolean}
Is the player is currently muted.
.getVolume() → {number}
Retrieve the current player volume.
.hideActivityIndicator()
Hide the player loading animation.
.insertMediaUnits(mediaUnits)
Append an array of MediaUnit or MediaEvent objects to the player playlist. Objects will be inserted right after the currently running unit.
Parameters:
-
mediaUnits
( Array.<(MediaUnit|MediaEvent)> )
.interrupt()
Pauses playback due to an external error.
.isStreamingLive() → {boolean}
Return a boolean value stating if the current stream is VOD or Livestream.
.next()
Proceed to the next unit in the playlist without signaling a skip.
.pause()
Pause playback.
.play()
Resume playback.
.playableDuration() → {number}
Retrieve the currently buffered duration.
.playbackState() → {PLAYBACK_STATE}
Returns the current playback state of the underlying video renderer.
- See:
Example
if (player.playbackState() === PLAYBACK_STATE.PLAYING) { console.log('Player is playing'); }
.playMediaUnits(mediaUnits)
Render a playlist of MediaUnit or MediaEvent objects.
Parameters:
-
mediaUnits
( Array.<(MediaUnit|MediaEvent)> )
.previous()
Unload current unit and load the previous unit in the playlist.
.setCurrentPlaybackTime(playbackTime)
Update the player position to a desired time.
Parameters:
-
playbackTime
( number )The desired position in seconds.
.setCurrentURL(url)
Replace a unit URL mid-playback.
Instructs the player to immediately load and play the new media URL.
This is useful when writing a UnitManager
that needs to
modify or customize a media URL.
Parameters:
-
url
( String )
- See:
.setMediaUnits(units)
Overwrites the current playlist.
Parameters:
-
units
( Array.<(MediaUnit|MediaEvent)> )
.setMute(bool)
Mute or unmute the player.
Parameters:
-
bool
( bool )
.setVolume(volume)
Update the player volume.
Parameters:
-
volume
( float )A float number between 0 (muted) and 1 (maximum volume).
.showActivityIndicator()
Display a loading animation on top of the player.
.skip()
Skip to the next element in the playlist.
.stop()
Unload the current unit and stop processing the playlist. Will signal that the user exited playback before completion.
.toggleFullscreen()
Toggle between fullscreen and inline mode.