Core Concepts
State Management
In this section, we'll look at the API available for reading and updating media state.
Reading
You can retrieve a snapshot of the current media state like so:
Subscribing
The <media-player>
element has a media store that keeps track of the running media state. The store enables you to subscribe directly to specific media state changes, rather than listening to potentially multiple DOM events and binding it yourself.
Tracking media state via events:
Tracking media state via store subscription:
You can create individual subscriptions if needed like so:
Updating
Media state updates can be requested directly on the player element like so:
All player properties and methods can be found in the <media-player>
API reference.
Media Remote
The MediaRemoteControl
class provides a simple facade for dispatching media request events. This can be used to request media playback to play/pause, change the current volume level, seek to a different time position, and other actions that change media state.
You can set a target to dispatch events from if you're performing actions without trigger events like so:
Player Element
The MediaRemoteControl
can attempt to find the nearest parent player element once a target has been attached like so: