Skip to main content

clearMediaSession

clearMediaSession(): void;

Take the current sound off the operating system's media controls.

Removes the metadata, unhooks every action handler and sets the playback state to none, so the lock screen stops showing a player. Call it when playback is finished for good, such as when a listener closes the episode or your component unmounts.

You do not need it between tracks. Calling setMediaSession again with new metadata replaces what is already there.

unloadSound on a stream that owns the media session calls this for you, so a player is never left pointing at audio that no longer exists.


Example

import { SoundHub } from 'soundhub';

const soundHub = new SoundHub();

// ...playing an episode with setMediaSession

function closePlayer() {
soundHub.stop('episode-42');
soundHub.clearMediaSession();
}

In a React component

useEffect(() => {
soundHub.setMediaSession('episode-42', { title: 'Episode 42' });
return () => soundHub.clearMediaSession();
}, []);