在iphone sdk中的youtube播放器中播放视频

时间:2011-06-20 09:29:08

标签: 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];
    }

你可以告诉我,代码中的问题是什么。

感谢。

1 个答案:

答案 0 :(得分:1)

iOS不支持Flash,您应该使用HTML 5的新标记video来打包视频网址:

<video src="point/to/mov"></video>