@capgo/capacitor-media-session

中文文档
8.1.8发布于 2026/11/09MPL-2.0TypeScriptESM + CJS零依赖构建来源已验证近 30 天下载 7.7万

Capacitor plugin to expose media session controls of the device

原始使用文档
文档目录13 节
  1. ➡️ Get started for free
  2. Key features
  3. Documentation
  4. Compatibility
  5. Install
  6. API
  7. setMetadata(...)
  8. setPlaybackState(...)
  9. setActionHandler(...)
  10. setPositionState(...)
  11. getPluginVersion()
  12. Interfaces
  13. Type Aliases

@capgo/capacitor-media-session

Show now-playing info and media controls on the lock screen, notification shade and control center for audio or video in your Capacitor app.

Capgo - Build Capacitor apps with AI, ship updates instantly

Capgo: push fixes to your Capacitor users in minutes, build signed iOS and Android apps without a Mac, and roll back in one click.

➡️ Get started for free

14-day unlimited free trial. No credit card required

🤖 Building with an AI coding agent? Install Capgo skills so Claude Code, Codex, Cursor, Copilot, or Gemini CLI know how to install and use @capgo/capacitor-media-session in your Capacitor app: npx skills add Cap-go/capgo-skills. Then ask your agent: "Add @capgo/capacitor-media-session to my Capacitor app and wire it up." Agent setup guides · Hosted MCP

@capgo/capacitor-media-session for Capacitor apps

Key features

  • Metadata: setMetadata() sets title, artist, album and artwork.
  • Playback state: setPlaybackState() shows playing, paused or none.
  • Remote controls: setActionHandler() handles play, pause, seek, next and previous.
  • Progress: setPositionState() updates duration, position and playback rate.
  • Platforms: iOS, Android and Web. iOS uses MediaPlayer now playing info, Android uses a media session service. Web uses the Media Session API.

Documentation

The most complete doc is available here: https://capgo.app/docs/plugins/media-session/

Compatibility

Plugin versionCapacitor compatibilityMaintained
v8.*.*v8.*.*✅
v7.*.*v7.*.*On demand
v6.*.*v6.*.*❌
v5.*.*v5.*.*❌

Note: The major version of this plugin follows the major version of Capacitor. Use the version that matches your Capacitor installation (e.g., plugin v8 for Capacitor 8). Only the latest major version is actively maintained.

Install

You can use our AI-Assisted Setup to install the plugin. Add the Capgo skills to your AI tool using the following command:

npx skills add https://github.com/cap-go/capacitor-skills --skill capacitor-plugins

Then use the following prompt:

Use the `capacitor-plugins` skill from `cap-go/capacitor-skills` to install the `@capgo/capacitor-media-session` plugin in my project.

If you prefer Manual Setup, install the plugin by running the following commands and follow the platform-specific instructions below:

npm install @capgo/capacitor-media-session
npx cap sync

API

setMetadata(...)

setMetadata(options: MetadataOptions) => Promise<void>

Sets metadata of the currently playing media.

ParamType
optionsMetadataOptions

setPlaybackState(...)

setPlaybackState(options: PlaybackStateOptions) => Promise<void>

Updates the playback state of the media session.

ParamType
optionsPlaybackStateOptions

setActionHandler(...)

setActionHandler(options: ActionHandlerOptions, handler: ActionHandler | null) => Promise<void>

Registers a handler for a media session action.

ParamType
optionsActionHandlerOptions
handlerActionHandler | null

setPositionState(...)

setPositionState(options: PositionStateOptions) => Promise<void>

Updates position state for the active media session.

ParamType
optionsPositionStateOptions

getPluginVersion()

getPluginVersion() => Promise<{ version: string; }>

Get the native Capacitor plugin version

Returns: Promise<{ version: string; }>


Interfaces

MetadataOptions

PropType
albumstring
artiststring
artworkMediaImage[]
titlestring

MediaImage

PropType
srcstring
sizesstring
typestring

PlaybackStateOptions

PropType
playbackStateMediaSessionPlaybackState

ActionHandlerOptions

PropType
actionMediaSessionAction

ActionDetails

PropType
actionMediaSessionAction
seekTimenumber | null

PositionStateOptions

PropType
durationnumber
playbackRatenumber
positionnumber

Type Aliases

MediaSessionPlaybackState

'none' | 'paused' | 'playing'

MediaSessionAction

'play' | 'pause' | 'seekbackward' | 'seekforward' | 'previoustrack' | 'nexttrack' | 'seekto' | 'stop'

ActionHandler

(details: ActionDetails): void

版本与发布记录

@capgo/capacitor-media-session 共发布 58 个版本,首次发布于 2025/10/10;过去 12 个月发布了 47 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
8.1.8latest2026/11/09今天
8.1.72026/11/026 天前
8.1.62026/10/2613 天前
8.1.52026/10/1920 天前
8.1.42026/10/1525 天前
8.1.32026/10/1327 天前

其他发布通道:lts-v7 → 7.3.0。

关于 @capgo/capacitor-media-session 的常见问题

@capgo/capacitor-media-session 是什么?

Capacitor plugin to expose media session controls of the device

如何安装 @capgo/capacitor-media-session?

在项目目录运行 npm install @capgo/capacitor-media-session,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@capacitor/core(>=8.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@capgo/capacitor-media-session 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@capgo/capacitor-media-session 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@capgo/capacitor-media-session 可以商用吗?

@capgo/capacitor-media-session 使用 MPL-2.0 许可。弱 Copyleft:可以商用,也可以和闭源代码一起使用;但如果分发时修改了 MPL 授权的文件,这些文件的修改需以 MPL 开源。以上为概括,不构成法律意见,请以许可原文为准。

@capgo/capacitor-media-session 的下载量有多少?

根据 npm 官方下载统计,@capgo/capacitor-media-session 在 2026/10/09 – 2026/11/07 这 30 天内被下载 76,657 次,日均约 2,555 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@capgo/capacitor-media-session 还在维护吗?

最新版本 8.1.8 发布于 2026/11/09(今天);至今共发布 58 个版本,其中过去 12 个月发布了 47 个;首次发布于 2025/10/10。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。