2011-06-21 28 views
0

我已經試過這下面的代碼來打開YouTube視頻,它不工作我可以知道原因,我不能能夠運行的YouTube視頻的iOS4.3

NSString *youTubeVideoHTML = @"<html><head>\ 
         <body style=\"margin:0\">\ 
         <embed id=\"yt\" src=\"http://www.youtube.com/watch?v=gczw0WRmHQU\" type=\"application/x-shockwave-flash\" \ 
         width=\"%0.0f\" height=\"%0.0f\"></embed>\ 
         </body></html>"; 

在此先感謝

回答

0

我猜你正在將該字符串加載到webview中,不是嗎?

/** 
* Embeds the youtube HTML data into the webview 
*/ 
- (void)embedYouTubeIntoWebview:(UIWebView *)webView 
         withURL:(NSString *)url 
         inFrame:(CGRect)frame { 
    webView.delegate = self; 
    NSString *embedHTML = 
    @"\ 
    <html><head>\ 
    <style type=\"text/css\">\ 
    body {\ 
    background-color: transparent;\ 
    color: white;\ 
    }\ 
    </style>\ 
    </head><body style=\"margin:0\">\ 
    <embed id=\"yt\" src=\"%@\" type=\"application/x-shockwave-flash\" \ 
    width=\"%0.0f\" height=\"%0.0f\"></embed>\ 
    </body></html>"; 
    NSString *html = 
    [NSString stringWithFormat:embedHTML, url, frame.size.width, frame.size.height]; 

    [webView loadHTMLString:html baseURL:nil]; 
} 

請記住,這不適用於模擬器。你需要在真實的設備上測試它。