Using @capgo/capacitor-media-session
Capacitor plugin to expose media session controls of the device.
Install
bun add @capgo/capacitor-media-session
bunx cap sync
bunx cap sync copies the plugin's native code into your native projects. Run it again after every plugin upgrade.
Import
import { MediaSession } from '@capgo/capacitor-media-session';
API at a glance
| Method | Description |
|---|---|
setMetadata |
Sets metadata of the currently playing media. |
setPlaybackState |
Updates the playback state of the media session. |
setActionHandler |
Registers a handler for a media session action. |
setPositionState |
Updates position state for the active media session. |
Examples
setMetadata()
Sets metadata of the currently playing media.
import { MediaSession } from '@capgo/capacitor-media-session';
await MediaSession.setMetadata({ album: 'album' });
setPlaybackState()
Updates the playback state of the media session.
import { MediaSession } from '@capgo/capacitor-media-session';
await MediaSession.setPlaybackState({ playbackState: 'none' });
setActionHandler()
Registers a handler for a media session action.
import { MediaSession } from '@capgo/capacitor-media-session';
await MediaSession.setActionHandler({ action: 'play' }, (details) => {
console.log(details);
});
setPositionState()
Updates position state for the active media session.
import { MediaSession } from '@capgo/capacitor-media-session';
await MediaSession.setPositionState({
duration: 1000,
playbackRate: 1,
position: 10,
});
Full reference
Keep going from Using @capgo/capacitor-media-session
If you are using Using @capgo/capacitor-media-session to plan dashboard and API operations, connect it with @capgo/capacitor-media-session for the implementation detail in @capgo/capacitor-media-session, Getting Started for the implementation detail in Getting Started, API Overview for the implementation detail in API Overview, Introduction for the implementation detail in Introduction, and API Keys for the implementation detail in API Keys.