iphone - 在iPhone SDK中的YouTube播放器中播放视频

标签 iphone objective-c xcode youtube

我编写了以下代码,以便在youtube嵌入式播放器中播放视频。
它打开播放器窗口并显示视频,但不播放。

if(self.isYouTube)
    {
        NSString *embedHTML;
        NSComparisonResult order = [[UIDevice currentDevice].systemVersion compare: @"4.3" options: NSNumericSearch];
        if (order == NSOrderedSame || order == NSOrderedDescending) {

            embedHTML = @"<html><head><style type=\"text/css\">body {background-color:black; color:black; margin-right:auto; margin-left:auto;}</style></head><body style=\"margin:0\"><embed id=\"yt\" src=\"%@\" airplay=\"allow\" type=\"application/x-shockwave-flash\" position=\"fixed\" allowfullscreen=\"true\" autoplay=\"1\" width=\"320.0\" height=\"460.0\"></embed></body></html>";

        } else {

            embedHTML = @"<html><head><style type=\"text/css\">body {background-color:black; color:black; margin-right:auto; margin-left:auto;}</style></head><body style=\"margin:0\"><embed id=\"yt\" src=\"%@\"  type=\"application/x-shockwave-flash\" position=\"fixed\" allowfullscreen=\"true\" autoplay=\"1\" width=\"320.0\" height=\"460.0\"></embed></body></html>";

        }


        NSString *contentHtml = [NSString stringWithFormat:embedHTML,self.url];

        [self.webView setBackgroundColor:[UIColor blackColor]];

        [self.webView loadHTMLString:contentHtml baseURL:nil];

        }
    else 
    {
        NSURL *urlForOpenFile=[NSURL URLWithString:self.url];
        NSURLRequest *request=[NSURLRequest requestWithURL:urlForOpenFile];
        [self.webView loadRequest:request];
    }

你能告诉我,代码中有什么问题。

谢谢。

最佳答案

iOS不支持Flash,您应该使用HTML 5的新标签video来包装视频网址,如下所示:
<video src="point/to/mov"></video>

关于iphone - 在iPhone SDK中的YouTube播放器中播放视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6409236/

相关文章:

ios - UIWebView 专注于特定方 block

objective-c - 为 CorePlot 制作 NSDecimal

swift - 为什么我的 pod 导入突然停止工作?

iphone - 核心数据迁移 xcode 4.2 未更新应用商店中已有应用的数据

iphone - 多个sks文件,在SpriteKit中根据GVC调用合适的场景

php - 未经身份验证发布 Twitter/Facebook 状态?

iphone - 如何在 UITableView 上延迟加载文本?

ios - 在状态恢复期间显示应用程序屏幕快照而不是启动屏幕

objective-c - 从返回NSArray的方法发出错误信号

ios - 核心数据并发类型未按预期工作