YouTube video playback broken on iOS6 (works fine on iOS5)

前端 未结 8 2189
南旧
南旧 2020-12-13 16:13

In my app, I have a button which, when pressed, lets you watch a youtube video (a movie trailer). Within the app, without launching safari. Below you can see a code snippet.

8条回答
  •  粉色の甜心
    2020-12-13 16:43

    I've found that the code below works for both iOS5 & iOS6. In my example, I have a text field that contains the url to the video. I first convert the formats to the same starting string 'http://m...". Then I check to see if the the format is the old format with the 'watch?v=' and then replace it with the new format. I've tested this on an iPhone with iOS5 and in the simulators in iOS5 & iOS6:

    -(IBAction)loadVideoAction {
        [activityIndicator startAnimating];
    
        NSString *urlString = textFieldView.text;
        urlString = [urlString stringByReplacingOccurrencesOfString:@"http://www.youtube" withString:@"http://m.youtube"];
        urlString = [urlString stringByReplacingOccurrencesOfString:@"http://m.youtube.com/watch?v=" withString:@""];
        urlString = [NSString stringWithFormat:@"%@%@", @"http://www.youtube.com/embed/", urlString];
        [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:urlString]]];
    }
    
    - (void)webViewDidFinishLoad:(UIWebView *)webView
    {
        [activityIndicator stopAnimating];
    }
    

提交回复
热议问题