__CAPGO_KEEP_2__

はじめに

GitHub

インストール

「インストール」

AI-Assisted Setupを使用してプラグインをインストールできます。AIツールにCapgoスキルを追加するには、以下のコマンドを実行してください。

ターミナル画面
npx skills add https://github.com/Cap-go/capgo-skills --skill capacitor-plugins

次に、以下のプロンプトを使用してください。

Use the `capacitor-plugins` skill from `Cap-go/capgo-skills` to install the `@capgo/capacitor-youtube-player` plugin in my project.

Manual Setupを使用する場合は、以下のコマンドを実行してください。プラットフォーム固有の指示に従ってください。

ターミナル画面
bun add @capgo/capacitor-youtube-player
bunx cap sync

インポート

「インポート」
import { YoutubePlayer } from '@capgo/capacitor-youtube-player';

メイン WebView で YouTube のリファラー ブロッキングを修正

メイン WebView で YouTube のリファラー ブロッキングを修正

YouTube がプラグイン内で動作する場合でも、同じアプリが YouTube のページ、埋め込み、または API を Capacitor のメイン WebView を通じて読み込むと失敗する場合、有効にします。 patchRefererHeader Capacitor の設定で "

Capacitor の Sync/Update 時に、インターセプトされた YouTube の要求に有効なヘッダーが含まれるようにプラグインが Capacitor をパッチします。 Referer クリップボードにコピー

{
"plugins": {
"YoutubePlayer": {
"patchRefererHeader": true,
"refererHeader": "https://www.youtube.com"
}
}
}
  • , および youtube.com, youtube-nocookie.com既にヘッダーを定義している要求は除外されます。 youtu.be 既にヘッダーを定義している要求は除外されます。
  • Requests Referer ヘッダーは元の値を保持します。
  • refererHeader は省略可能であり、デフォルト値は https://www.youtube.com.
  • サポートされるプラットフォームはCapacitor 8.x インストール済みのiOSおよびAndroidプラットフォーム向けです。

新しいYouTubeプレイヤーインスタンスを初期化します。

import { YoutubePlayer } from '@capgo/capacitor-youtube-player';
await YoutubePlayer.initialize({
playerId: 'my-player',
videoId: 'dQw4w9WgXcQ',
playerSize: { width: 640, height: 360 },
privacyEnhanced: true
});

プレイヤーインスタンスを破棄し、リソースを解放します。

import { YoutubePlayer } from '@capgo/capacitor-youtube-player';
await YoutubePlayer.destroy({} as PlayerIdOptions);

動画の再生を停止し、ロードをキャンセルします。 このメソッドを頻繁に使用するのは避けてください。pauseVideo()を使用することが推奨されます。

import { YoutubePlayer } from '@capgo/capacitor-youtube-player';
await YoutubePlayer.stopVideo({} as PlayerIdOptions);

現在のキューまたはロード済みの動画を再生します。 最終的なプレイヤー状態はPLAYING(1)になります。

import { YoutubePlayer } from '@capgo/capacitor-youtube-player';
await YoutubePlayer.playVideo({} as PlayerIdOptions);

現在の再生中の動画を一時停止します。 最終的なプレイヤー状態はPAUSED(2)になります。ただし、既にENDED(0)の場合は除きます。

import { YoutubePlayer } from '@capgo/capacitor-youtube-player';
await YoutubePlayer.pauseVideo({} as PlayerIdOptions);

動画の特定の時間にジャンプします。 プレイヤーが一時停止中の場合は一時停止が維持され、再生中の場合は再生が継続されます。

import { YoutubePlayer } from '@capgo/capacitor-youtube-player';
await YoutubePlayer.seekTo({} as SeekToOptions);

指定されたYouTube IDで動画を読み込んで再生します。

import { YoutubePlayer } from '@capgo/capacitor-youtube-player';
await YoutubePlayer.loadVideoById({} as VideoByIdMethodOptions);

IDで動画をクイューする サムネイルを読み込んでプレーヤーを準備しますが、再生するにはplayVideo()を呼び出す必要があります。

import { YoutubePlayer } from '@capgo/capacitor-youtube-player';
await YoutubePlayer.cueVideoById({} as VideoByIdMethodOptions);

指定されたURLで動画を読み込んで再生します。

import { YoutubePlayer } from '@capgo/capacitor-youtube-player';
await YoutubePlayer.loadVideoByUrl({} as VideoByUrlMethodOptions);

URLで動画をクイューする サムネイルを読み込んでプレーヤーを準備しますが、再生するにはplayVideo()を呼び出す必要があります。

import { YoutubePlayer } from '@capgo/capacitor-youtube-player';
await YoutubePlayer.cueVideoByUrl({} as VideoByUrlMethodOptions);

プレイリストをクエストする

import { YoutubePlayer } from '@capgo/capacitor-youtube-player';
await YoutubePlayer.cuePlaylist({} as PlaylistMethodOptions);

プレイリストを読み込んで再生する

import { YoutubePlayer } from '@capgo/capacitor-youtube-player';
await YoutubePlayer.loadPlaylist({} as PlaylistMethodOptions);

プレイリストの次の動画を再生する

import { YoutubePlayer } from '@capgo/capacitor-youtube-player';
await YoutubePlayer.nextVideo({} as PlayerIdOptions);

プレイリストの前の動画を再生する

import { YoutubePlayer } from '@capgo/capacitor-youtube-player';
await YoutubePlayer.previousVideo({} as PlayerIdOptions);

プレイリスト内の特定の動画を指定されたインデックスで再生します。

import { YoutubePlayer } from '@capgo/capacitor-youtube-player';
await YoutubePlayer.playVideoAt({} as PlayVideoAtOptions);

プレイヤーアウディオをミュートします。

import { YoutubePlayer } from '@capgo/capacitor-youtube-player';
await YoutubePlayer.mute({} as PlayerIdOptions);

プレイヤーアウディオをアンミュートします。

import { YoutubePlayer } from '@capgo/capacitor-youtube-player';
await YoutubePlayer.unMute({} as PlayerIdOptions);

プレイヤーが現在ミュート状態であるかを確認します。

import { YoutubePlayer } from '@capgo/capacitor-youtube-player';
await YoutubePlayer.isMuted({} as PlayerIdOptions);

プレイヤーの音量を設定します。

import { YoutubePlayer } from '@capgo/capacitor-youtube-player';
await YoutubePlayer.setVolume({} as SetVolumeOptions);

現在のプレイヤーの音量を取得します。 ミュート状態でも音量を取得します。

import { YoutubePlayer } from '@capgo/capacitor-youtube-player';
await YoutubePlayer.getVolume({} as PlayerIdOptions);

プレイヤーのサイズをピクセル単位で設定します。

import { YoutubePlayer } from '@capgo/capacitor-youtube-player';
await YoutubePlayer.setSize({} as SetSizeOptions);

現在の再生速度を取得します。

import { YoutubePlayer } from '@capgo/capacitor-youtube-player';
await YoutubePlayer.getPlaybackRate({} as PlayerIdOptions);

再生速度を設定します。

import { YoutubePlayer } from '@capgo/capacitor-youtube-player';
await YoutubePlayer.setPlaybackRate({} as SetPlaybackRateOptions);

現在の動画の再生速度の選択肢を取得します。

import { YoutubePlayer } from '@capgo/capacitor-youtube-player';
await YoutubePlayer.getAvailablePlaybackRates({} as PlayerIdOptions);

ループ機能を有効または無効にします。 ループが有効になっている場合、最後の動画の終了後は再生が開始されます。

import { YoutubePlayer } from '@capgo/capacitor-youtube-player';
await YoutubePlayer.setLoop({} as SetLoopOptions);

シャッフル機能を有効または無効にします。

import { YoutubePlayer } from '@capgo/capacitor-youtube-player';
await YoutubePlayer.setShuffle({} as SetShuffleOptions);

ビデオのバッファリングされた部分の割合を取得します。 より信頼性の高いgetVideoBytesLoaded/getVideoBytesTotalの代替

import { YoutubePlayer } from '@capgo/capacitor-youtube-player';
await YoutubePlayer.getVideoLoadedFraction({} as PlayerIdOptions);

プレイヤーの現在の状態を取得します。

import { YoutubePlayer } from '@capgo/capacitor-youtube-player';
await YoutubePlayer.getPlayerState({} as PlayerIdOptions);

すべてのアクティブなプレイヤーのイベント状態を取得します。 複数のプレイヤー インスタンスを追跡するのに役立ちます。

import { YoutubePlayer } from '@capgo/capacitor-youtube-player';
await YoutubePlayer.getAllPlayersEventsState();

現在の再生位置(秒)を取得します。

import { YoutubePlayer } from '@capgo/capacitor-youtube-player';
await YoutubePlayer.getCurrentTime({} as PlayerIdOptions);

フルスクリーンモードをオンまたはオフにします。

import { YoutubePlayer } from '@capgo/capacitor-youtube-player';
await YoutubePlayer.toggleFullScreen({} as ToggleFullScreenOptions);

getPlaybackQuality

再生品質の取得

コピー

import { YoutubePlayer } from '@capgo/capacitor-youtube-player';
await YoutubePlayer.getPlaybackQuality({} as PlayerIdOptions);

コピー

import { YoutubePlayer } from '@capgo/capacitor-youtube-player';
await YoutubePlayer.setPlaybackQuality({} as SetPlaybackQualityOptions);

getAvailableQualityLevels

コピー

利用可能な品質レベルの取得

import { YoutubePlayer } from '@capgo/capacitor-youtube-player';
await YoutubePlayer.getAvailableQualityLevels({} as PlayerIdOptions);

現在の動画の秒数を取得します。

import { YoutubePlayer } from '@capgo/capacitor-youtube-player';
await YoutubePlayer.getDuration({} as PlayerIdOptions);

現在の動画のYouTube.com URLを取得します。

import { YoutubePlayer } from '@capgo/capacitor-youtube-player';
await YoutubePlayer.getVideoUrl({} as PlayerIdOptions);

Get the embed code for the current video. Returns HTML iframe embed code.

import { YoutubePlayer } from '@capgo/capacitor-youtube-player';
await YoutubePlayer.getVideoEmbedCode({} as PlayerIdOptions);

現在のプレイリスト内の動画IDの配列を取得します。

import { YoutubePlayer } from '@capgo/capacitor-youtube-player';
await YoutubePlayer.getPlaylist({} as PlayerIdOptions);

プレイリストで現在再生中の動画のインデックスを取得します。

import { YoutubePlayer } from '@capgo/capacitor-youtube-player';
await YoutubePlayer.getPlaylistIndex({} as PlayerIdOptions);

プレイヤーのiframe DOM要素を取得します。 Webプラットフォームのみ。

import { YoutubePlayer } from '@capgo/capacitor-youtube-player';
await YoutubePlayer.getIframe({} as PlayerIdOptions);

イベントリスナーをプレイヤーに追加します。 Webプラットフォームのみ。

import { YoutubePlayer } from '@capgo/capacitor-youtube-player';
YoutubePlayer.addEventListener({
playerId: 'my-player',
eventName: 'onStateChange',
listener: (event) => {
console.log('Player state:', event.data);
},
});

イベントリスナーをプレイヤーから削除します。 Webプラットフォームのみ。

import { YoutubePlayer } from '@capgo/capacitor-youtube-player';
await YoutubePlayer.removeEventListener({} as PlayerEventListenerOptions<TEvent>);

種類の参照

「種類の参照」

PlayerIdOptions

「PlayerIdOptions」
export interface PlayerIdOptions {
playerId: string;
}

SeekToOptions

「SeekToOptions」
export interface SeekToOptions extends PlayerIdOptions {
playerId: string;
seconds: number;
allowSeekAhead: boolean;
}

VideoByIdMethodOptions

「VideoByIdMethodOptions」
export interface VideoByIdMethodOptions extends PlayerIdOptions {
playerId: string;
options: IVideoOptionsById;
}

VideoByUrlMethodOptions

「VideoByUrlMethodOptions」
export interface VideoByUrlMethodOptions extends PlayerIdOptions {
playerId: string;
options: IVideoOptionsByUrl;
}

PlaylistMethodOptions

「PlaylistMethodOptions」
export interface PlaylistMethodOptions extends PlayerIdOptions {
playerId: string;
playlistOptions: IPlaylistOptions;
}
export interface PlayVideoAtOptions extends PlayerIdOptions {
playerId: string;
index: number;
}
export interface SetVolumeOptions extends PlayerIdOptions {
playerId: string;
volume: number;
}
export interface SetSizeOptions extends PlayerIdOptions {
playerId: string;
width: number;
height: number;
}
export interface SetPlaybackRateOptions extends PlayerIdOptions {
playerId: string;
suggestedRate: number;
}
export interface SetLoopOptions extends PlayerIdOptions {
playerId: string;
loopPlaylists: boolean;
}
export interface SetShuffleOptions extends PlayerIdOptions {
playerId: string;
shufflePlaylist: boolean;
}
export interface ToggleFullScreenOptions extends PlayerIdOptions {
playerId: string;
isFullScreen: boolean | null | undefined;
}

真実の源

真実の源

このページはプラグインの src/definitions.ts. 公開 API がアップストリームで変更されたときに再度 Sync を実行してください。

Getting Started から続けてください

Getting Started から続けてください

あなたが Getting Started ダッシュボードと API の作業を計画する場合、 Using @capgo/capacitor-youtube-player native機能の使用に@capgo/capacitor-youtube-playerのために APIの概要 APIの実装詳細のために 導入 __CAPGO_KEEP_0__の実装詳細のために APIのキー APIの実装詳細のために、 デバイス ページを編集