【问题标题】:play vidoes in youtube player in iphone sdk在 iphone sdk 的 youtube 播放器中播放视频
【发布时间】:2011-09-18 13:11:51
【问题描述】:

我编写了如下代码来播放 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];
    }

你能告诉我,代码有什么问题吗?

谢谢。

【问题讨论】:

    标签: iphone objective-c xcode youtube


    【解决方案1】:

    iOS 不支持 flash,你应该使用 HTML 5 的新标签 video 来包装视频 url,如下所示:

    &lt;video src="point/to/mov"&gt;&lt;/video&gt;

    【讨论】:

    • 这不是真的,您仍然可以在 youtube 播放器中播放来自 youtube 的嵌入内容。 iOs 不支持 flash 是真的。
    • 反正..模拟器和设备也玩不了
    • 确保您的视频网址可在 iOS 上播放,即 mov 或 mp4 格式,而不是 flv。
    • @xan 您的回答对嵌入式代码有何影响?我在播放 youtube 视频时遇到了一些问题(有些视频正在播放,有些没有)
    猜你喜欢
    • 2014-05-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-29
    • 2015-02-16
    • 1970-01-01
    • 1970-01-01
    • 2014-09-27
    • 2012-04-02
    相关资源
    最近更新 更多