Media Session API. Native control for web applications.
We at Zattoo are pioneers in the streaming sphere. It’s not always easy to deal with the unknown, it still feels like an exciting journey of taming the wilderness.
Being early adopters of technologies helps us better react to upcoming challenges and continuously improve the experience for our users, as we did it with PWA, Voice Control, Casting experience, etc.
This March, we are introducing Media Session support.
What is Media Session?
Media Session API allows a web application to show customized media metadata on platform UI, customize available platform media controls, and access platform media keys, such as hardware keys (found on keyboards), headsets, remote controls, and software keys (found in notification areas and on lock screens of mobile devices).
How does it work?
Generally, the browser detects unmuted audio or video and displays its meta-information with the ability to control playback. Let’s take a more detailed look.
Meta Information
We can provide three text fields: album, artist, and title.
To populate this information, we need to assign a new instance of window.MediaMetadata to metadata.
And Artwork as multiple images collection.
To change metadata, you can rewrite it and assign a new one.
To clean metadata, you can assign it to null.
Actions
A media session action is an action that the page can handle in order for the user to interact with the
MediaSession
Play & Pause
These actions would be set by default anyway, but if you want to control or forbid them, you can set next.
Seek backward & forward
Allows moving playback time by a short period
Previous & Next
Allowing navigation within a playlist. Or in our case, to zap through channels list.
Close
Always present, closes media controls panel. If the handler provided, this control will also close playback.
Skip Ad
This allows skipping the advertisement that is currently playing by the specification. However, we have not found support for this handler yet.
Set Position
This part of API allows us to provide correct timing to the progress bar and control it as range control.
Support
- Chrome 73. Full control over position included in Chrome 81+, more details
- Samsung Internet 7+
- Firefox announced support, but we have yet to see it
Why do we care?
If you do not support Media Session API, there are generally no negative consequences.
For instance, when you watch some Netflix content on Chrome desktop, the browser is going to try to do the best it can from what it has.
But if your application is not ready to be controlled from outer UI, you may have an unexpected experience. For example, let’s interact with a live stream on Joyn
That is quite an issue when you legally disallowed or not plan to support pause or replay functionality for live streams.
Conclusion
In conclusion, let us share the findings from our users’ behaviors. Surprisingly, some of our customers are using live streams to listen to sports events, while the app is playing in a pocket, when they are busy walking, driving, or doing something that requires visual attention.
Option to control our app with physical controls could be quite a nice addition to such experience.
Take a look at how it works on zattoo.com
References
- W3C Specification Standard
- MDN. Navigator.mediaSession
- Google Blog. Manage audio and video in Chrome with one click
- OTT. Media Session API: the input of Chrome’s Global Media Controls
- Sample. Chrome Video / Media Session
- Open PR to support Media Session in TypeScript
- Update: web.dev. Customize media notifications and playback controls with the Media Session API