2012-04-05 69 views
0

播放嵌入你管的视频我在急难排序玩你管的视频在我的iPhone 5 ... 我使用此代码对这个问题:如何在iOS5中

urls = [urls stringByAppendingString:@"&autoplay=1"]; 
NSString *htmlString =[NSString stringWithFormat: @"<html><head> <meta name = \"viewport\" content = \"initial-scale = 1.0, user-scalable = no, width = 212\"/></head> <body style=\"background:#F00;margin-top:0px;margin-left:0px\"><div><object width=\"212\" height=\"212\"><param name=\"movie\" value=\"%@\">",urls]; 

NSString *htm2=[NSString stringWithFormat:@"</param><param name=\"wmode\" value=\"transparent\"></param> <embed src=\"%@\"type=\"application/x-shockwave-flash\" wmode=\"transparent\" width=\"212\" height=\"212\"></embed> </object></div></body></html>",urls]; 
// NSString* embedHTML = @"<html><head> </head><body style=\"margin:0\"> <iframe title=\"YouTube video player\" class=\"youtube-player\" type=\"text/html\" width=\"%d\" height=\"%d\" src=\"%@\" frameborder=\"0\" allowFullScreen></iframe> </body></html>"; 

NSString* html = [NSString stringWithFormat:@"%@%@",htmlString,htm2]; 
NSLog(@"Html - %@",urls); 
float version = [[[UIDevice currentDevice] systemVersion] floatValue]; 


if(version <= 5.0) 
{ 

    NSRange r=[urls rangeOfString:@"v="]; 
    NSRange ran=NSMakeRange(r.location+2, [urls length]-r.location-2); 
    NSString *vid=[urls substringWithRange:ran]; 
    html=[NSString stringWithFormat:@"<embed id=\"yt\" src=\"http://www.youtube.com/watch?v=%@&fs=0\" type=\"application/x-shockwave-flash\" width=\"300\" height=\"300\"></embed>", vid]; 
} 
//NSLog(html); 

[videoView loadHTMLString:html baseURL:nil]; 

灿有谁请帮我解决这个问题? 您的帮助将不胜感激。

回答

0

?如果是,则删除自动播放视频的代码。检查你的HTML。使用balh而不是。还有一件事,请检查浏览器上的视频URL确认视频是否存在j

+0

谢谢所有..它删除自动播放逻辑后工作。 – 2012-04-09 09:25:16

0

按照下面的链接,您已经自动使用web视图的委托方法用于播放视频,你会得到这个工作

http://apiblog.youtube.com/2009/02/youtube-apis-iphone-cool-mobile-apps.html

http://iphoneincubator.com/blog/audio-video/how-to-play-youtube-videos-within-an-application

+0

感谢您的帮助,但我已经尝试过这些链接,但问题是,这是不适用于iOS5设备。它显示空白Webview。 – 2012-04-05 07:04:18

+0

好吧,你有没有尝试过这个os4,然后检查 – 2012-04-05 07:06:29

+0

是的,在ios4的情况下,它正在工作... – 2012-04-05 09:55:51