2012-04-05 24 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