开发者

iOS5, uiwebview, and video

Does anyone know why the following, that worked so well all the way to 4.3, now doesn't work with the iOS5 SDK (and is there a way to get it to work)? I have a general purpose video player that uses this scheme to play multiple formats and Youtube, and would like to keep using it. It just doesn't load the video (even though the webview finishes loading). In iOS5 it does still load and play Youtube videos, just no HTTP Live Streams or non-Youtube videos (i.e., mp4's).

It works fine if I build with iOS4.3 and run it on an iOS5 device (iPad). It fails when I build with the iOS5 SDK. NOTE: I kept XCODE 3.x and iOS 4.3 around just in case.

On another note, I can get the HTML5 video tag to play the live stream and mp4's, but cannot get it to resize, no matter how many widths and heights I use.

Anyway, here is the code (UIWebview):

static NSString* kEmbedHTML = @"<html><开发者_StackOverflow中文版head><meta name=\"viewport\" content=\"initial-scale=1.0, user-scalable=no, width=%0.0f, height=%0.0f\"/></head><body style=\"background:#fff;margin-top:0px;margin-left:0px\"><div><object width=\"%0.0f\" height=\"%0.0f\"><param name=\"movie\" value=\"%@\"></param><param name=\"wmode\"value=\"transparent\"></param><embed id=\"yt\" airplay=\"allow\" src=\"%@\" type=\"application/x-shockwave-flash\" wmode=\"transparent\" width=\"%0.0f\" height=\"%0.0f\"></embed></object></div></body></html>";

....

- (void)layoutSubviews {
[self stringByEvaluatingJavaScriptFromString:
 [NSString stringWithFormat:@"controls.width = %0.0f; controls.height = %0.0f", kDefaultWidth,kDefaultHeight]];
}

....

NSString* html = [NSString stringWithFormat:kEmbedHTML, kDefaultWidth, kDefaultHeight, kDefaultWidth, kDefaultHeight, _urlPath, _urlPath, kDefaultWidth, kDefaultHeight];
[self loadHTMLString:html baseURL:nil] ;


try replacing "embed" with "iframe" in your html

if it works for your non-youtube stuff, you can make your youtube links work with this by replacing "watch?v=" with "embed/" in the link code


The only solution I could find was to sniff the type of URL (i.e, Youtube) and use loadRequest for the non-Youtube stuff, and loadHTMLString for the Youtube stuff.

Pretty hacky, but it works for me and gets me past this iOS5 grief.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜