I'm trying to use YTPlayer for played live stream in iOS App.
I use the simple code and only changed 'videoId' to 'w-T2LJ_qLiw' which is live video at YouTube.
But when video loaded, app will open Safari and redirect to URL as following:
and
Then video will loaded and played but covered will black block shows 'Please stand by.'
If video is not 'live', video plays well.
I tried it before yesterday and it works well. What happened to YTPlayer?
I needs to control video's action like, play, pause, reload by code.
Is there any thing I can work around this?
Although 周義棠's solution may work, it breaks YouTube's Terms of Service. I have modified the handleHttpNavigationToUrl:
method to check for these two additional URLs before taking the user out of the UIWebView and into Safari.
This is my working solution:
// 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;
}
}
I have also proposed this change on the project's GitHub as PR #111.
EDIT 6/10/15: As of today, this modification has been merged into the codebase.