ios - 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
解决方案
尝试将origin
参数添加到您的playerVars
dictionary
,即
NSDictionary *playerVars = @{
@"controls" : @0,
@"playsinline" : @1,
@"autohide" : @1,
@"showinfo" : @0,
@"modestbranding" : @1,
@"origin":@"https://www.youtube.com"
};
从YouTube
API 文档,
Origin:此参数为 IFrame API 提供额外的安全措施,仅支持 IFrame 嵌入。如果您使用的是 IFrame API,这意味着您将 enablejsapi 参数值设置为 1,则应始终将您的域指定为源参数值。
你可以在这里阅读更多关于它的信息。
推荐阅读
- vue.js - Vue路由器 - 克服下一个({})未捕获(承诺)未定义错误
- spring - 在 Spring 中动态解析静态内容
- python - logger.setLevel 没有效果
- c - 优先队列和堆(这对我来说很难......)
- bash - 将 stat 命令输出与 bash 中的字符串进行比较
- azure-devops - 如何使用 REST API 更新任务组
- xamarin - 使用 SKCanvasView 渲染图块网格
- django - django.core.exceptions.AppRegistryNotReady:加载 wsgi.py 时尚未加载应用程序
- docker - docker:已安装卷的权限错误
- c# - 在漫游时随机移动 Picturebox