Getting Started
Copy a setup prompt with the install steps and the full markdown guide for this plugin.
Set up this Capacitor plugin in the project.
Use the package manager already used by the project.
Install these package(s): `@capgo/capacitor-media-session`
Run the required Capacitor sync/update step after installation.
Read this markdown guide for the full setup steps: https://raw.githubusercontent.com/Cap-go/website/refs/heads/main/apps/docs/src/content/docs/docs/plugins/media-session/getting-started.mdx
Use that guide for platform-specific steps, native file edits, permissions, config changes, imports, and usage setup.
If that guide references other docs pages, read them too.
Install
Section titled “Install”bun add @capgo/capacitor-media-sessionbunx cap syncImport
Section titled “Import”import { MediaSession } from '@capgo/capacitor-media-session';API Overview
Section titled “API Overview”setMetadata
Section titled “setMetadata”Sets metadata of the currently playing media.
import { MediaSession } from '@capgo/capacitor-media-session';
await MediaSession.setMetadata({} as MetadataOptions);setPlaybackState
Section titled “setPlaybackState”Updates the playback state of the media session.
import { MediaSession } from '@capgo/capacitor-media-session';
await MediaSession.setPlaybackState({} as PlaybackStateOptions);setActionHandler
Section titled “setActionHandler”Registers a handler for a media session action.
import { MediaSession } from '@capgo/capacitor-media-session';
await MediaSession.setActionHandler({} as ActionHandlerOptions, {} as ActionHandler | null);setPositionState
Section titled “setPositionState”Updates position state for the active media session.
import { MediaSession } from '@capgo/capacitor-media-session';
await MediaSession.setPositionState({} as PositionStateOptions);Type Reference
Section titled “Type Reference”MetadataOptions
Section titled “MetadataOptions”export interface MetadataOptions { album?: string; artist?: string; artwork?: MediaImage[]; title?: string;}PlaybackStateOptions
Section titled “PlaybackStateOptions”export interface PlaybackStateOptions { playbackState: MediaSessionPlaybackState;}ActionHandlerOptions
Section titled “ActionHandlerOptions”export interface ActionHandlerOptions { action: MediaSessionAction;}ActionHandler
Section titled “ActionHandler”export type ActionHandler = (details: ActionDetails) => void;PositionStateOptions
Section titled “PositionStateOptions”export interface PositionStateOptions { duration?: number; playbackRate?: number; position?: number;}MediaImage
Section titled “MediaImage”export interface MediaImage { src: string; sizes?: string; type?: string;}MediaSessionPlaybackState
Section titled “MediaSessionPlaybackState”export type MediaSessionPlaybackState = 'none' | 'paused' | 'playing';MediaSessionAction
Section titled “MediaSessionAction”export type MediaSessionAction = | 'play' | 'pause' | 'seekbackward' | 'seekforward' | 'previoustrack' | 'nexttrack' | 'seekto' | 'stop';Source Of Truth
Section titled “Source Of Truth”This page is generated from the plugin’s src/definitions.ts. Re-run the sync when the public API changes upstream.