LoginSignup
9
11

More than 5 years have passed since last update.

YouTube-Player-iOS-Helperを使ってvevoの動画を再生

Last updated at Posted at 2015-08-23

無知すぎてiOSでのyoutubeのvevo動画が再生ができずに、適当にぐぐった結果、上手くいったので備忘録。
日本語での情報源を探せなかったのでqiitaに投稿。

iOSでyoutube動画を再生するためのライブラリ「YouTube-Player-iOS-Helper」を使ってvevoの動画を再生。
恐らく、ライブラリ使わずともUIWebviewを用いるとできそうな?気がする。

youtubeでの解説ページ

GitHub

因みにGitHubのページだと

pod "youtube-ios-player-helper", "~> 0.1.4"

上記だと自分の環境ではインストールできず

pod "youtube-ios-player-helper", "~> 0.1.3"

でいけました。cocoapodsだと0.1.4は対応していない。

コード

#import "YTPlayerView.h"

NSString *videoId = @"IxxstCcJlsc";//適宜、動画IDを設定

NSDictionary *playerVars = @{
                             @"playsinline" : @1,
                             @"autoplay" : @0,                             
                             @"origin" : @"https://www.youtube.com/" //これを設定しないと再生できない
                             };

YTPlayerView *playerView = [[YTPlayerView alloc] initWithFrame:CGRectMake(0, 0, 320, 180)];
playerView.center = self.view.center;//中央配置(画面回転の考慮なし)
[self.view addSubview:playerView];

[playerView loadWithVideoId:videoId playerVars:playerVars];

バックグラウンド再生

実際、申請していないので、どうなるかは不明。
なんかグレーそうで怖い。

9
11
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
9
11