Skip to main content

API

Available through the player instance. To get it, create a player:

const player = await oberplayer(document.querySelector('#player_container')).setup({
playlist: [
{
videoUrl: 'https://cdn.oberplayer.com/fixtures/mp4/bbb_27s_4k.mp4'
}
]

Now, call any function as follows:

player.api.setVolume(0.5);

Function reference


play()

Description

Use the video provider play function. It returns a Promise, which is resolved when playback has been successfully started. A failure to begin playback for any reason, such as permission issues, leads to a rejected Promise.

Parameters

Parameters
None

Return value

DescriptionType
Promise result (nothing or error)Promise

Example

player.api.play().then(() => {
console.log('Play call succeeded')
}).catch((err) => {
console.error(error)
})

pause()

Parameters

Parameters
None

Return value

Description
None

togglePlay()

Description

Toggles player state from paused to playing and from playing to paused

Parameters

Parameters
None

Return value

Description
Same as play() or pause() according to the initial player state

seek()

Description

Moves the current playback to the given position in seconds

Parameters

| Parameters | Type | | ----------- | | Position in seconds | Number |

Return value

Description
None

getPosition()

Description

Return the current playback position in seconds

Parameters

Parameters
None

Return value

DescriptionType
Position in secondsNumber
caution

With live videos, the position returned will be the DVR position, if any.


getVolume()

Description

Returns the current video volume from 0 to 1

Parameters

Parameters
None

Return value

DescriptionType
Volume from 0 to 1Number
caution

Volume is independent of the mute state. A volume value of 1 doesn't mean that the sound can be heard.


setVolume()

Description

Sets the current video volume to the given value

Parameters

Parameters
Volume

Return value

Description
None
caution

Same notice as getVolume()


getDuration()

Description

Returns the duration of the video in seconds. Live video duration is always -1.

Parameters

Parameters
None

Return value

Description
Duration in seconds

getMute()

Description

Returns muted state of the video.

Parameters

Parameters
None

Return value

DescriptionType
Muted stateBoolean

setMute()

Description

Sets the video to the given muted state

Parameters

ParametersType
MutedBoolean

Return value

Description
None

toggleMute()

Description

Inverts the muted state of the video

Parameters

Parameters
None

Return value

Description
None

toggleFullScreen()

Description

Inverts the fullscreen state of the video

Parameters

Parameters
None

Return value

Description
None
tip

Some limitations could apply because of browser policies (See https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Permissions-Policy/fullscreen)


getState()

Description

Returns the player's state

Parameters

Parameters
None

Return value

DescriptionType
'paused', 'ended', 'playing'String

setPlaybackRate()

Description

Sets the rate at which the media is being played back. 1.0 is "normal speed". Values lower than 1.0 make the media play slower than normal and higher values make it play faster.

Parameters

Parameters
Speed

Return value

Description
None