2011-10-05 125 views
1
- (void)embedYouTube:(NSString*)url frame:(CGRect)frame { 

    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=\"100\" height=\"100\">\ 
    <param name=\"movie\" value=\"%@\"></param>\ 
    <param name=\"wmode\" value=\"transparent\"></param>\ 
    <embed src=\"%@\"\ 
    type=\"application/x-shockwave-flash\" wmode=\"transparent\" width=\"100\" height=\"100\"></embed>\ 
    </object></div></body></html>",url,url]; 

    webView = [[UIWebView alloc] initWithFrame:frame]; 
    webView.delegate = self; 
    [webView setScalesPageToFit:TRUE]; 
    [webView setContentMode:UIViewContentModeTop]; 
    [self.view addSubview:webView]; 
    [webView loadHTMLString:htmlString baseURL:nil]; 

} 

我已經實現了上面的代碼。它在iPhone上運行良好,但在iPad上我只聽到音頻,視頻不顯示。如何嵌入ipad的視頻網址

如何在兩種類型的設備上進行此項工作?

回答

1

我工作了兩個多天後得到解決...... 解決方案是,我需要在視圖中添加控制器與iphone不同。 但是請記住一件事,就是在解散視圖的同時寫下這兩行。

[webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"about:blank"]]]; 
0

這將做伎倆。試試下面的代碼:

(請注意,它只會在設備上工作,而不是模擬器)

NSURL *videoURL = [NSURL URLWithString: @"http://www.youtube.com/embed/iyKsSPHM0wE"]; 



    NSURLCache *sharedCache = [[NSURLCache alloc] initWithMemoryCapacity:0 diskCapacity:0 diskPath:nil]; 
    [NSURLCache setSharedURLCache:sharedCache]; [sharedCache release]; 
    // 

    NSURLRequest *request = [[NSURLRequest alloc] initWithURL: videoURL cachePolicy: NSURLRequestReloadIgnoringLocalCacheData timeoutInterval: 30.0]; 
    [webView loadRequest: request]; 
    [request release]; 
+0

感謝您的回放,但它不能這樣做,因爲它不能像播放器一樣在播放器中直接播放視頻,並在設備(真正的iPhone或iPod)中播放。 –