gpt4 book ai didi

ios - YTPlayer将重定向到OAuth2 URL并显示“请稍候”

转载 作者:行者123 更新时间:2023-12-01 16:33:24 25 4
gpt4 key购买 nike

我正在尝试使用YTPlayer在iOS App中播放直播。

我使用简单的代码,仅将“videoId”更改为“w-T2LJ_qLiw”,这是YouTube上的实时视频。

但是,当视频加载后,应用程序将打开Safari并重定向到URL,如下所示:

https://accounts.google.com/o/oauth2/postmessageRelay?parent=https%3A%2F%2Fwww.youtube.com#rpctoken=840721360&forcesecure=1



https://content.googleapis.com/static/proxy.html?jsh=m%3B%2F_%2Fscs%2Fabc-static%2F_%2Fjs%2Fk%3Dgapi.gapi.en.dPxK-DAj_pE.O%2Fm%3D__features__%2Fam%3DAAQ%2Frt%3Dj%2Fd%3D1%2Frs%3DAItRSTN0fuoBkyFaoHWfzWWLct0BxZgQSQ#parent=https%3A%2F%2Fwww.youtube.com&rpctoken=2021820196

然后将加载并播放视频,但会被黑色方框显示“请稍候”。

如果视频不是“实时”的,则视频播放良好。

我昨天之前尝试过,效果很好。 YTPlayer发生了什么?
我需要通过代码控制视频的操作,例如播放,暂停,重新加载。
有什么我可以解决的吗?

最佳答案

尽管周义棠的解决方案可能有效,但它违反了YouTube的服务条款。我修改了handleHttpNavigationToUrl:方法,以在将用户带出UIWebView并进入Safari之前检查这两个其他URL。

这是我的工作解决方案:

// YTPlayerView.m

// ...

NSString static *const kYTPlayerOAuthRegexPattern = @"^http(s)://accounts.google.com/o/oauth2/(.*)$";
NSString static *const kYTPlayerStaticProxyRegexPattern = @"^https://content.googleapis.com/static/proxy.html(.*)$";

// ...

- (BOOL)handleHttpNavigationToUrl:(NSURL *) url {
// Usually this means the user has clicked on the YouTube logo or an error message in the
// player. Most URLs should open in the browser. The only http(s) URL that should open in this
// UIWebView is the URL for the embed, which is of the format:
// http(s)://www.youtube.com/embed/[VIDEO ID]?[PARAMETERS]
NSError *error = NULL;
NSRegularExpression *ytRegex =
[NSRegularExpression regularExpressionWithPattern:kYTPlayerEmbedUrlRegexPattern
options:NSRegularExpressionCaseInsensitive
error:&error];
NSTextCheckingResult *ytMatch =
[ytRegex firstMatchInString:url.absoluteString
options:0
range:NSMakeRange(0, [url.absoluteString length])];

NSRegularExpression *adRegex =
[NSRegularExpression regularExpressionWithPattern:kYTPlayerAdUrlRegexPattern
options:NSRegularExpressionCaseInsensitive
error:&error];
NSTextCheckingResult *adMatch =
[adRegex firstMatchInString:url.absoluteString
options:0
range:NSMakeRange(0, [url.absoluteString length])];

NSRegularExpression *oauthRegex =
[NSRegularExpression regularExpressionWithPattern:kYTPlayerOAuthRegexPattern
options:NSRegularExpressionCaseInsensitive
error:&error];
NSTextCheckingResult *oauthMatch =
[oauthRegex firstMatchInString:url.absoluteString
options:0
range:NSMakeRange(0, [url.absoluteString length])];

NSRegularExpression *staticProxyRegex =
[NSRegularExpression regularExpressionWithPattern:kYTPlayerStaticProxyRegexPattern
options:NSRegularExpressionCaseInsensitive
error:&error];
NSTextCheckingResult *staticProxyMatch =
[[staticProxyRegex firstMatchInString:url.absoluteString
options:0
range:NSMakeRange(0, [url.absoluteString length])];

if (ytMatch || adMatch || oauthMatch || staticProxyMatch) {
return YES;
} else {
[[UIApplication sharedApplication] openURL:url];
return NO;
}
}

我还已在项目的GitHub上将此更改建议为PR #111

编辑6/10/15:到今天为止,此修改已合并到代码库中。

关于ios - YTPlayer将重定向到OAuth2 URL并显示“请稍候”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30482280/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com