iOS5、uiwebview 和视频

发布于 2024-12-09 17:21:02 字数 1538 浏览 1 评论 0原文

有谁知道为什么下面的内容一直到 4.3 都运行得很好,现在却不能与 iOS5 SDK 一起使用(有没有办法让它工作)?我有一个通用视频播放器,使用此方案来播放多种格式和 Youtube,并希望继续使用它。它只是不加载视频(即使网络视图完成加载)。在 iOS5 中,它仍然可以加载和播放 Youtube 视频,只是没有 HTTP 直播流或非 Youtube 视频(即 mp4 的)。

如果我使用 iOS4.3 进行构建并在 iOS5 设备 (iPad) 上运行它,则效果很好。当我使用 iOS5 SDK 构建时,它失败了。注意:我保留了 XCODE 3.x 和 iOS 4.3,以防万一。

另一方面,我可以获取 HTML5 视频标签来播放实时流和 mp4,但无法调整其大小,无论我使用多少宽度和高度。

无论如何,这是代码(UIWebview)

static NSString* kEmbedHTML = @"<html><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] ;

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><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] ;

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

风渺 2024-12-16 17:21:02

如果它适用于您的非 YouTube 内容,请尝试在 html 中将“embed”替换为“iframe”

,您可以通过在链接代码中将“watch?v=”替换为“embed/”来使您的 YouTube 链接与此兼容

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

看轻我的陪伴 2024-12-16 17:21:02

我能找到的唯一解决方案是嗅探 URL 的类型(即 Youtube),并对非 Youtube 内容使用 loadRequest,对 Youtube 内容使用 loadHTMLString。

相当老套,但它对我有用,让我摆脱了 iOS5 的悲伤。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文