I'm using a UIWebView on iPhone to play YouTube videos. This is working fine most of the time, but not all开发者_JAVA百科.
Under some circumstances, apparently related to network connection issues, the error "This movie format is not supported." is shown. This same error can be seen in both Safari and the YouTube player under the same circumstances.
Unfortunately it has been seen by Apple during the AppStore testing so they've rejected the app.
Can anyone suggest methods for detecting and handling the error more appropriately or alternatively any other video hosting system where we could get a similar experience without the player issue?
Thanks for your help,
Larry
Try this code to see if it gives you any other hints about the problem:
// report the error inside the webview
NSString* errorString = [NSString stringWithFormat:
@"<html><center><font size=+5 color='white'>An error occurred:<br>%@</font></center></html>",
error.localizedDescription];
[self.webView loadHTMLString:errorString baseURL:nil];
If you use the YouTube data api and inspect the syndicate key, if it's TRUE then the video should play.
When this value is set to FALSE, it indicates that the video is restricted on mobile devices.
Assuming youTubeResults is a youtube jsonc encoded NSDictionary
if (![[[[[[youTubeResults objectForKey:@"data"]
objectForKey:@"items"]
objectAtIndex:index]
objectForKey:@"accessControl"]
valueForKey:@"syndicate"] isEqualToString:@"allowed"]){
NSLog(@"video won't play on mobile!");
}
Also, you could try using this uiwebview category I've developed, you might be setting up the uiwebview differently that I do. As, I haven't seen that error.
https://github.com/enigmaticflare/UIWebView-YouTube--iOS-Category--ARC-compliant-code
精彩评论