Skip to content

Module: src/controller/MediaSession

The MediaSession component bridges VisionPlayer with the browser Media Session API. It populates the session metadata (title and artwork) as soon as media data is ready and wires chapter data to next/previous track actions when available.

Version
1.0.0
Author
Frank Kudermann - alphanull
License
MIT
Source
MediaSession.js, line 10

Constructor

new MediaSession(player)

Creates an instance of the MediaSession component.

Parameters:
Name Type Description
player Player

Reference to the VisionPlayer instance.

Members

Reference to the main player instance.

Type
Player
Source
MediaSession.js, line 16

Holds tokens of subscriptions to player events, for later unsubscribe.

Type
Array<number>
Source
MediaSession.js, line 22

Reference to the current MediaSession instance.

Type
MediaSession
Source
MediaSession.js, line 28

Normalized list of chapters for quick lookup.

Type
Array<Data~mediaItem_chapter>
Source
MediaSession.js, line 34

Methods

private #onDataUpdate(updateopt) → void

Central handler to (re)apply metadata and chapter state. Accepts full media objects or partial data/update fragments.

Parameters:
Name Type Attributes Default Description
update Object optional {}

Full media item or partial update fragment.

Returns
Type void
Source
MediaSession.js, line 77

private #resetMetadata()

Clears session metadata.

Listens
data/nomedia
Source
MediaSession.js, line 125

private #onNextPlaylist()

Handler for "next track" action: advances playlist.

Source
MediaSession.js, line 136

private #onPreviousPlaylist()

Handler for "previous track" action: moves playlist backward.

Source
MediaSession.js, line 149

private #onPlayAction()

Handler for "play" action via Media Session.

Source
MediaSession.js, line 162

private #onPauseAction()

Handler for "pause" action via Media Session.

Source
MediaSession.js, line 171

private #updatePlaybackState(state)

Sets mediaSession playbackState if available.

Parameters:
Name Type Description
state 'none' | 'paused' | 'playing'

Playback state.

Listens
media/play
media/pause
media/ended
Source
MediaSession.js, line 184

private #onSeekTo(detailsopt)

Handler for "seekto" action via Media Session.

Parameters:
Name Type Attributes Description
details Object optional

Seek details provided by Media Session.

Source
MediaSession.js, line 194

private #onTimeUpdate()

Updates mediaSession position state if supported; skipped for live.

Listens
media/timeupdate
Source
MediaSession.js, line 207

private #onNextChapter()

Handler for "seek forward" action, mapped to next chapter.

Source
MediaSession.js, line 229

private #onPreviousChapter()

Handler for "seek backward" action, mapped to chapter rewind.

Source
MediaSession.js, line 245

private #getChapterIndex(time) → number

Finds the active chapter index for the given playback time.

Parameters:
Name Type Description
time number

Current playback time in seconds.

Returns

Chapter index.

Type number
Source
MediaSession.js, line 263

private #seekToChapter(index)

Seeks the media element to a chapter start time.

Parameters:
Name Type Description
index number

Chapter index to seek to.

Source
MediaSession.js, line 278

destroy()

This method removes all events, subscriptions and DOM nodes created by this component.

Source
MediaSession.js, line 289