2011-10-05 123 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)中播放。 –