首页 > 解决方案 > YTPlayerView 不在模拟器上播放内容(解码失败,错误代码)

问题描述

当我播放普通内容时,它在模拟器上加载得非常好。

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

标签: iosobjective-cyoutube-apiios-simulator

解决方案


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

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

YouTubeAPI 文档,

Origin:此参数为 IFrame API 提供额外的安全措施,仅支持 IFrame 嵌入。如果您使用的是 IFrame API,这意味着您将 enablejsapi 参数值设置为 1,则应始终将您的域指定为源参数值。

你可以在这里阅读更多关于它的信息。


推荐阅读