play vidoes in youtube player in iphone sdk
I wrote the code as follows to play the videos in youtube开发者_Python百科 embedded player . It opens the player window and shows the vidoe , but does not play .
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];
}
can u tell me , what's the problem in the code.
Thanks.
iOS doesn't support flash, you should use the HTML 5's new tag video
to wrap the video url like this:
<video src="point/to/mov"></video>
精彩评论