YoutubeVideoPlayerはIonicNativeの一部であり、Cordovaプラグインの厳選されたリストのラッパーのセットです。 これらのラッパーを使用すると、アプリにネイティブ機能を非常に簡単に実装できます。 ここでは、Youtubeビデオプレーヤーをセットアップする方法を見てみましょう。

まず、YoutubeVideoPlayerCordovaプラグインをインストールします。

$ ionic plugin add https://github.com/Glitchbone/CordovaYoutubeVideoPlayer.git

次に、それをコンポーネントにインポートします。

import { YoutubeVideoPlayer } from 'ionic-native';

これで、 openVideo()メソッドを使用できます。

playVideo(videoId) {
  YoutubeVideoPlayer.openVideo(videoId);
}

そして今、あなたのテンプレートでは、有効なYoutubeビデオIDで playVideo()を呼び出すのと同じくらい簡単です:

<input placeholder="Enter a video id" #videoId>
<button ion-button (click)="openVideo(videoId.value)">
  <ion-icon name="play"></ion-icon>
</button>