YTPlayerView 不在模拟器上播放内容(解码失败,错误代码)

YTPlayerView does not play Content on Simulator (Decoding failed with error code)

当我播放普通内容时,它在 模拟器。

YTPlayerView 参数

@implementation SingleVideoViewController

- (void)viewDidLoad {
  [super viewDidLoad];
  NSString *videoId = @"weRHyjj34ZE";

  // For a full list of player parameters, see the documentation for the HTML5 player
  // at: https://developers.google.com/youtube/player_parameters?playerVersion=HTML5
  NSDictionary *playerVars = @{
      @"controls" : @0,
      @"playsinline" : @1,
      @"autohide" : @1,
      @"showinfo" : @0,
      @"modestbranding" : @1
  };
  self.playerView.delegate = self;
  [self.playerView loadWithVideoId:videoId playerVars:playerVars];



  [[NSNotificationCenter defaultCenter] addObserver:self
                                           selector:@selector(receivedPlaybackStartedNotification:)
                                               name:@"Playback started"
                                             object:nil];

}

但是,如果我的播放列表中有高清视频,则会出现以下错误和代码 https://github.com/youtube/youtube-ios-player-helper

代码可用于 Git 项目,只需下载它并更改 SingleVideoViewController 中的 videoId。

Decoding failed with error code -1
Decoding: C0 0x01E00168 0x0000304A 0x22111100 0x00000000 6668
Options: 1x-1 [0000002D,01E0010F] 0001C060
Decoding failed with error code 7
Decoding: C0 0x01E00168 0x0000304A 0x22111100 0x00000000 773
Options: 1x-1 [0000002D,01E0010F] 0001C060
Decoding failed with error code -1
Decoding: C0 0x01E00168 0x0000304A 0x22111100 0x00000000 773
Options: 480x360 [FFFFFFFF,FFFFFFFF] 0001C060

尝试将 origin 参数添加到您的 playerVars dictionary,即

NSDictionary *playerVars = @{
      @"controls" : @0,
      @"playsinline" : @1,
      @"autohide" : @1,
      @"showinfo" : @0,
      @"modestbranding" : @1,
      @"origin":@"https://www.youtube.com"
  };

来自 YouTube API 文档,

Origin: This parameter provides an extra security measure for the IFrame API and is only supported for IFrame embeds. If you are using the IFrame API, which means you are setting the enablejsapi parameter value to 1, you should always specify your domain as the origin parameter value.

您可以阅读更多相关信息 here