@capgo/capacitor-video-player

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

Capacitor plugin to play video in native player

原始使用文档
文档目录34 节
  1. ➡️ Get started for free
  2. Key features
  3. Documentation
  4. Compatibility
  5. Install
  6. iOS Chromecast setup
  7. Supported Features
  8. Chromecast (Android)
  9. Chromecast Options
  10. Requirements and Notes
  11. Android Picture in Picture
  12. iOS Picture in Picture and background audio
  13. API
  14. initPlayer(...)
  15. isPlaying(...)
  16. play(...)
  17. pause(...)
  18. getDuration(...)
  19. getCurrentTime(...)
  20. setCurrentTime(...)
  21. getVolume(...)
  22. setVolume(...)
  23. getMuted(...)
  24. setMuted(...)
  25. setRate(...)
  26. getRate(...)
  27. stopAllPlayers()
  28. showController()
  29. isControllerIsFullyVisible()
  30. exitPlayer()
  31. hidePlayer()
  32. showPlayer()
  33. getPluginVersion()
  34. Interfaces

@capgo/capacitor-video-player

Play videos in a native fullscreen player in your Capacitor app, with subtitles, picture in picture and Chromecast support.

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-video-player in your Capacitor app: npx skills add Cap-go/capgo-skills. Then ask your agent: "Add @capgo/capacitor-video-player to my Capacitor app and wire it up." Agent setup guides · Hosted MCP

@capgo/capacitor-video-player for Capacitor apps

Key features

  • Players: initPlayer() creates a player for a URL, with play(), pause() and stopAllPlayers().
  • Playback control: setCurrentTime(), setVolume(), setMuted() and setRate(), with matching getters.
  • Subtitles: one or more subtitle tracks with language options.
  • Native extras: picture in picture, background mode, loop on end and Chromecast casting.
  • Controller: showController() and isControllerIsFullyVisible() for the native controls.
  • Platforms: iOS, Android and Web. Web also supports an embedded player mode.

Documentation

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

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-video-player` plugin in my project.

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

bun add @capgo/capacitor-video-player
bunx cap sync

iOS Chromecast setup

iOS Chromecast uses the Google Cast SDK default media receiver. When chromecast is enabled, the plugin adds a Cast button over the fullscreen iOS player, loads the current media on the selected receiver, and keeps plugin play/pause/seek/volume calls pointed at the active Cast session.

For Cast discovery on iOS, add local network keys to your app Info.plist.

<key>NSBonjourServices</key>
<array>
  <string>_googlecast._tcp</string>
  <string>_CC1AD845._googlecast._tcp</string>
</array>
<key>NSLocalNetworkUsageDescription</key>
<string>$(PRODUCT_NAME) uses the local network to discover Cast-enabled devices on your WiFi network.</string>
await VideoPlayer.initPlayer({
  playerId: 'fullscreen',
  mode: 'fullscreen',
  url: 'https://example.com/video.mp4',
  title: 'Video title',
  smallTitle: 'Video subtitle',
  artwork: 'https://example.com/poster.jpg',
  chromecast: true,
});

Supported Features

FeatureiOSAndroidWeb
Fullscreen native video player✅✅❌
Embedded web video player❌❌✅
Picture in Picture✅✅❌
Subtitles✅✅✅
DRM-protected playback✅✅❌
Chromecast sender playback❌✅❌

Chromecast (Android)

Chromecast is supported on Android in fullscreen mode. Enable it with the chromecast option. When a Cast session starts, the plugin loads the same media URL on the receiver, keeps the current playback position, and routes play, pause, seek, and timeline controls through the Cast session.

await VideoPlayer.initPlayer({
  mode: 'fullscreen',
  playerId: 'main-player',
  url: 'https://example.com/video.m3u8',
  title: 'Video title',
  smallTitle: 'Optional subtitle',
  artwork: 'https://example.com/artwork.jpg',
  chromecast: true,
  showControls: true,
});

Chromecast Options

OptionTypeDefaultDescription
chromecastbooleantrueShows the Android Cast button and enables sender playback.
titlestring""Title shown in the sender controls and receiver metadata.
smallTitlestring""Subtitle shown in the sender controls and metadata.
artworkstring""Image URL used for Cast metadata and sender Cast artwork.

Requirements and Notes

  • The media URL must be reachable by the Chromecast device, not only by the Android app.
  • Cast support depends on the receiver app and device media support. MP4, HLS, DASH, and SmoothStreaming streams are mapped to Cast-compatible MIME types by the plugin.
  • Widevine DRM metadata is forwarded to the Cast media item. DRM-protected streams may still require a receiver that supports your license server and DRM flow.
  • Request headers used by the Android local player are not automatically available to the Chromecast receiver. Use public URLs, signed URLs, cookies supported by your receiver, or a custom receiver for secured media.

Android Picture in Picture

Picture in Picture on Android requires your app activity to declare PiP support in android/app/src/main/AndroidManifest.xml:

<activity
  android:name=".MainActivity"
  android:supportsPictureInPicture="true"
  android:launchMode="singleTask"
  android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|smallestScreenSize|screenLayout|uiMode|navigation|density"
  ...>
</activity>

launchMode="singleTask" and the configChanges flags prevent the player activity from being recreated when entering or leaving PiP.

iOS Picture in Picture and background audio

On iOS the native player configures AVAudioSession for PiP and background playback when pipEnabled or bkmodeEnabled is true (both default to true). Your app still needs the right plist and capability entries:

  1. In Xcode, add the Background Modes capability and enable Audio, AirPlay, and Picture in Picture.
  2. In ios/App/App/Info.plist, include the audio background mode:
<key>UIBackgroundModes</key>
<array>
  <string>audio</string>
</array>

Test PiP on a physical iPhone (the Simulator does not support Picture in Picture). Setting audioCategory: 'ambient' respects the silent switch but silences audio on screen lock; leave it unset or use playback for audible background playback.

API

initPlayer(...)

initPlayer(options: capVideoPlayerOptions) => Promise<capVideoPlayerResult>

Initialize a video player

ParamType
optionscapVideoPlayerOptions

Returns: Promise<capVideoPlayerResult>


isPlaying(...)

isPlaying(options: capVideoPlayerIdOptions) => Promise<capVideoPlayerResult>

Return if a given playerId is playing

ParamType
optionscapVideoPlayerIdOptions

Returns: Promise<capVideoPlayerResult>


play(...)

play(options: capVideoPlayerIdOptions) => Promise<capVideoPlayerResult>

Play the current video from a given playerId

ParamType
optionscapVideoPlayerIdOptions

Returns: Promise<capVideoPlayerResult>


pause(...)

pause(options: capVideoPlayerIdOptions) => Promise<capVideoPlayerResult>

Pause the current video from a given playerId

ParamType
optionscapVideoPlayerIdOptions

Returns: Promise<capVideoPlayerResult>


getDuration(...)

getDuration(options: capVideoPlayerIdOptions) => Promise<capVideoPlayerResult>

Get the duration of the current video from a given playerId

ParamType
optionscapVideoPlayerIdOptions

Returns: Promise<capVideoPlayerResult>


getCurrentTime(...)

getCurrentTime(options: capVideoPlayerIdOptions) => Promise<capVideoPlayerResult>

Get the current time of the current video from a given playerId

ParamType
optionscapVideoPlayerIdOptions

Returns: Promise<capVideoPlayerResult>


setCurrentTime(...)

setCurrentTime(options: capVideoTimeOptions) => Promise<capVideoPlayerResult>

Set the current time to seek the current video to from a given playerId

ParamType
optionscapVideoTimeOptions

Returns: Promise<capVideoPlayerResult>


getVolume(...)

getVolume(options: capVideoPlayerIdOptions) => Promise<capVideoPlayerResult>

Get the volume of the current video from a given playerId

ParamType
optionscapVideoPlayerIdOptions

Returns: Promise<capVideoPlayerResult>


setVolume(...)

setVolume(options: capVideoVolumeOptions) => Promise<capVideoPlayerResult>

Set the volume of the current video to from a given playerId

ParamType
optionscapVideoVolumeOptions

Returns: Promise<capVideoPlayerResult>


getMuted(...)

getMuted(options: capVideoPlayerIdOptions) => Promise<capVideoPlayerResult>

Get the muted of the current video from a given playerId

ParamType
optionscapVideoPlayerIdOptions

Returns: Promise<capVideoPlayerResult>


setMuted(...)

setMuted(options: capVideoMutedOptions) => Promise<capVideoPlayerResult>

Set the muted of the current video to from a given playerId

ParamType
optionscapVideoMutedOptions

Returns: Promise<capVideoPlayerResult>


setRate(...)

setRate(options: capVideoRateOptions) => Promise<capVideoPlayerResult>

Set the rate of the current video from a given playerId

ParamType
optionscapVideoRateOptions

Returns: Promise<capVideoPlayerResult>


getRate(...)

getRate(options: capVideoPlayerIdOptions) => Promise<capVideoPlayerResult>

Get the rate of the current video from a given playerId

ParamType
optionscapVideoPlayerIdOptions

Returns: Promise<capVideoPlayerResult>


stopAllPlayers()

stopAllPlayers() => Promise<capVideoPlayerResult>

Stop all players playing

Returns: Promise<capVideoPlayerResult>


showController()

showController() => Promise<capVideoPlayerResult>

Show controller

Returns: Promise<capVideoPlayerResult>


isControllerIsFullyVisible()

isControllerIsFullyVisible() => Promise<capVideoPlayerResult>

isControllerIsFullyVisible

Returns: Promise<capVideoPlayerResult>


exitPlayer()

exitPlayer() => Promise<capVideoPlayerResult>

Exit player

Returns: Promise<capVideoPlayerResult>


hidePlayer()

hidePlayer() => Promise<capVideoPlayerResult>

Hide the currently presented player UI without stopping playback (native fullscreen).

Call showPlayer() to show it again.

Returns: Promise<capVideoPlayerResult>


showPlayer()

showPlayer() => Promise<capVideoPlayerResult>

Show again a previously hidden player UI (native fullscreen).

Returns: Promise<capVideoPlayerResult>


getPluginVersion()

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

Get the native Capacitor plugin version. On web, the implementation returns "web".

Returns: Promise<{ version: string; }>


Interfaces

capVideoPlayerResult

PropTypeDescription
resultbooleanresult set to true when successful else false
methodstringmethod name
valueanyvalue returned
messagestringmessage string

capVideoPlayerOptions

PropTypeDescription
modestringPlayer mode - "fullscreen" - "embedded" (Web only)
urlstringThe url of the video to play
chromecastUrlstringOptional override URL used when casting to Chromecast (iOS, Android). This lets you cast an alternative rendition/manifest (e.g. MPEG-DASH + Widevine) while keeping the on-device playback URL unchanged (e.g. HLS + FairPlay on iOS).
subtitlestringThe url of subtitle associated with the video Prefer subtitles when providing more than one track. Kept for backward compatibility.
languagestringThe language of subtitle see https://github.com/libyal/libfwnt/wiki/Language-Code-identifiers Prefer subtitles when providing more than one track. Kept for backward compatibility.
subtitlesVideoSubtitle[]Multiple subtitle tracks (iOS, Android). When provided, takes precedence over subtitle / language.
chaptersVideoChapter[]Chapter markers for long-form content (iOS, Android). Shown as a chapter list in the native fullscreen player; selecting a chapter seeks to startTime.
subtitleOptionsSubTitleOptionsSubTitle Options
playerIdstringId of DIV Element parent of the player
ratenumberInitial playing rate
exitOnEndbooleanExit on VideoEnd (iOS, Android) default: true
loopOnEndbooleanLoop on VideoEnd when exitOnEnd false (iOS, Android) default: false
pipEnabledbooleanPicture in Picture Enable (iOS, Android) default: true
bkmodeEnabledbooleanBackground Mode Enable (iOS, Android) default: true
audioCategory'ambient' | 'playback' | 'moviePlayback'iOS audio session category behavior (iOS). - "ambient": respects the iPhone silent switch - "playback": ignores the iPhone silent switch - "moviePlayback": playback optimized for video and long-form AirPlay. When omitted, the plugin resolves the category from other options: "playback" if pipEnabled or bkmodeEnabled is true (both default to true), otherwise "ambient".
showControlsbooleanShow Controls Enable (iOS, Android) default: true
displayModestringDisplay Mode ["all", "portrait", "landscape"] (iOS, Android) default: "all"
componentTagstringComponent Tag or DOM Element Tag (React app)
widthnumberPlayer Width (mode "embedded" only)
heightnumberPlayer height (mode "embedded" only)
headers{ [key: string]: string; }Headers for the request (iOS, Android) by Manuel García Marín (https://github.com/PhantomPainX)
titlestringTitle shown in the player and Chromecast metadata (iOS, Android) by Manuel García Marín (https://github.com/PhantomPainX)
smallTitlestringSubtitle shown below the title in the player and Chromecast metadata (iOS, Android) by Manuel García Marín (https://github.com/PhantomPainX)
accentColorstringExoPlayer Progress Bar and Spinner color (Android) by Manuel García Marín (https://github.com/PhantomPainX) Must be a valid hex color code default: #FFFFFF
chromecastbooleanChromecast enable/disable (iOS, Android) iOS requires Google Cast SDK setup and local network Info.plist keys. by Manuel García Marín (https://github.com/PhantomPainX) default: true
artworkstringArtwork url to be shown in Chromecast player (iOS, Android) by Manuel García Marín (https://github.com/PhantomPainX) default: ""
drmDrmOptionsDRM configuration for protected content (iOS: FairPlay, Android: Widevine) When casting, Widevine's certificateUrl (license URL) is also forwarded to Chromecast receivers as media.customData.laurl.

VideoSubtitle

PropTypeDescription
subtitlestringThe url of the subtitle file (vtt, srt, ...)
languagestringThe language of the subtitle see https://github.com/libyal/libfwnt/wiki/Language-Code-identifiers

VideoChapter

PropTypeDescription
titlestringChapter title shown in the chapter list
startTimenumberStart time in seconds
endTimenumberEnd time in seconds (optional). Stored for future timeline markers; chapter jumps use startTime only in this release.

SubTitleOptions

Optional styling for on-screen subtitles.

On iOS, colors and font size are applied through AVPlayerItem textStyleRules, which Apple documents for WebVTT only. IMSC1 and other in-manifest timed text formats are not styled through this API. Inline WebVTT cue styles can take precedence over equivalent subtitleOptions values; the plugin sets text style rules as a platform fallback, not a guaranteed override of authored cue styling.

PropTypeDescription
foregroundColorstringForeground color in RGBA. On Android, when the plugin applies subtitle styling, omitted values fall back to rgba(255,255,255,1). When subtitleOptions is absent, embedded cue colors from the media can override that fallback. On iOS, omitted colors are not set by the plugin; the platform uses the viewer's caption appearance settings instead of fixed plugin defaults.
backgroundColorstringBackground color in RGBA. On Android, when the plugin applies subtitle styling in fullscreen, omitted values fall back to rgba(0,0,0,1). In picture-in-picture, omitted values fall back to transparent when the plugin applies its caption style (for example sidecar subtitles or non-empty subtitleOptions that include a color override). An empty subtitleOptions object alone does not select that fallback. With font-size-only options, embedded cue styles stay enabled, so authored cue backgrounds can remain visible in PiP. When subtitleOptions is absent, embedded cue colors from the media can override the fallback. On iOS, omitted colors are not set by the plugin; the platform uses the viewer's caption appearance settings instead of fixed plugin defaults.
fontSizenumberFont size in CSS pixels. On Android, supplied values are rounded to the nearest integer before applying. When omitted on embedded tracks without a sidecar subtitle URI, Android uses SubtitleView.setUserDefaultTextSize() (the user's system caption size), not a fixed 16 px size. Sidecar subtitles still use a fixed default size when this property is omitted. On iOS, values map to AVFoundation relative size where 16 equals the system default (100%).

DrmOptions

PropTypeDescription
fairplayFairPlayDrmOptionsFairPlay DRM configuration (iOS)
playreadyPlayreadyDrmOptionsPlayReady DRM configuration
widevineWidevineDrmOptionsWidevine DRM configuration (Android)

FairPlayDrmOptions

PropTypeDescription
certificateUrlstringThe URL to fetch the FairPlay certificate
contentKeySpcUrlstringThe URL to send the SPC and receive the CKC license (FairPlay license server URL)
assetIdstringOptional FairPlay asset identifier used when generating the SPC. Defaults to the skd:// content identifier from the key request.

PlayreadyDrmOptions

PropTypeDescription
certificateUrlstringThe URL to fetch the PlayReady license

WidevineDrmOptions

PropTypeDescription
certificateUrlstringThe URL to fetch the Widevine license

capVideoPlayerIdOptions

PropTypeDescription
playerIdstringId of DIV Element parent of the player

capVideoTimeOptions

PropTypeDescription
playerIdstringId of DIV Element parent of the player
seektimenumberVideo time value you want to seek to

capVideoVolumeOptions

PropTypeDescription
playerIdstringId of DIV Element parent of the player
volumenumberVolume value between [0 - 1]

capVideoMutedOptions

PropTypeDescription
playerIdstringId of DIV Element parent of the player
mutedbooleanMuted value true or false

capVideoRateOptions

PropTypeDescription
playerIdstringId of DIV Element parent of the player
ratenumberRate value

版本与发布记录

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

版本发布日期距今
8.3.0latest2026/11/044 天前
8.2.152026/10/1723 天前
8.2.142026/10/1525 天前
8.2.132026/10/1327 天前
8.2.122026/10/091 个月前
8.2.112026/10/081 个月前

关于 @capgo/capacitor-video-player 的常见问题

@capgo/capacitor-video-player 是什么?

Capacitor plugin to play video in native player

如何安装 @capgo/capacitor-video-player?

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

@capgo/capacitor-video-player 支持 TypeScript 吗?

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

@capgo/capacitor-video-player 支持 ESM 还是 CommonJS?

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

@capgo/capacitor-video-player 可以商用吗?

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

@capgo/capacitor-video-player 的下载量有多少?

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

@capgo/capacitor-video-player 还在维护吗?

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