ios7 UIWebView Youtube Video

前端 未结 5 571
滥情空心
滥情空心 2021-02-04 10:33

I have a UIWebView subclass that I used to play both youtube and local videos. Worked perfectly under iOS6. In upgrading to iOS7 I\'ve encountered a problem I don\'t really kn

5条回答
  •  情歌与酒
    2021-02-04 11:17

    Try this:

    NSString* videoUrl = @"//www.youtube.com/embed/Of_hjbYCx4Y";
    if([videoUrl hasPrefix:@"//"]) {
        videoUrl = [NSString stringWithFormat:@"https:%@", videoUrl]; // or http
        // if its a local file add proper scheme like "file:///"
    }
    NSString* iframeWidth = @"100%";
    NSString* iframeHeight = @"240px";
    NSString *iframeHTML =[NSString stringWithFormat:@"", iframeWidth, iframeHeight, videoUrl];
    // you can directly use iframeHTML below or u can wrap it up in body and span tags and then use it if u need to add any extra stuff or customize the page itself
    [videoWebView loadHTMLString:htmlString baseURL:nil];
    

    Make sure of two things: Video url starts with http (proper scheme) and replace the /watch?v= with embed/ if u don't have it already in url. Check other answers given here to see how to do this. Hope it helps.

提交回复
热议问题