createMediaSession
function createMediaSession(__namedParameters): MediaSessionController;
Create a media session, presenting the ongoing call to the platform's media controls, e.g. the lock screen, the notification shade or headset buttons.
Declaring a media session also hints the browser that the page is playing media, which mobile browsers use to relax the throttling applied to backgrounded pages and to keep the audio capture alive.
Every method is a no-op when the Media Session API is unavailable, so the caller does not need to feature detect it.
Parameters
| Parameter | Type |
|---|---|
__namedParameters | MediaSessionInit |
Returns
Example
const session = createMediaSession({
metadata: {title: 'Weekly sync', artist: 'Pexip'},
handlers: {
hangup: () => leaveMeeting(),
togglemicrophone: () => toggleAudioMuted(),
},
});
await session.setMicrophoneActive(true);
session.destroy();