Skip to main content
Back to plugins
@capgo/capacitor-youtube-player
Tutorial
by github.com/Cap-go

YouTube Player

Embed YouTube videos with full player API control and event handling

Guide

Tutorial on YouTube Player

Using @capgo/capacitor-youtube-player

YouTube Player Plugin interface for Capacitor. Provides methods to control YouTube video playback in your app.

Install

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

What This Plugin Exposes

  • initialize - Initialize a new YouTube player instance.
  • destroy - Destroy a player instance and free resources.
  • stopVideo - Stop video playback and cancel loading. Use this sparingly - pauseVideo() is usually preferred.
  • playVideo - Play the currently cued or loaded video. Final player state will be PLAYING (1).

Example Usage

initialize

Initialize a new YouTube player instance.

import { YoutubePlayer } from '@capgo/capacitor-youtube-player';

await YoutubePlayer.initialize({
  playerId: 'my-player',
  videoId: 'dQw4w9WgXcQ',
  playerSize: { width: 640, height: 360 },
  privacyEnhanced: true
});

destroy

Destroy a player instance and free resources.

import { YoutubePlayer } from '@capgo/capacitor-youtube-player';

await YoutubePlayer.destroy({} as PlayerIdOptions);

stopVideo

Stop video playback and cancel loading. Use this sparingly - pauseVideo() is usually preferred.

import { YoutubePlayer } from '@capgo/capacitor-youtube-player';

await YoutubePlayer.stopVideo({} as PlayerIdOptions);

playVideo

Play the currently cued or loaded video. Final player state will be PLAYING (1).

import { YoutubePlayer } from '@capgo/capacitor-youtube-player';

await YoutubePlayer.playVideo({} as PlayerIdOptions);

Full Reference