2012-08-12 85 views
0

嵌入式UIWebview中的Youtube視頻。如何在UIButton按下時使用UIWebview播放此管視頻。使用UIWebview播放嵌入式YouTube視頻

- (void)viewDidLoad 
{ 
CGRect rect = [[UIScreen mainScreen] bounds]; 
CGSize screenSize = rect.size; 

UIWebView *webView = [[UIWebView alloc]initWithFrame:CGRectMake(0,0,screenSize.width,screenSize.height)]; 
webView.autoresizesSubviews = YES; 
webView.autoresizingMask=(UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth); 

NSString *videoUrl = @"http://http://www.youtube.com/v/oHg5SJYRHA0"; 
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=\"320\" height=\"480\"><param name=\"movie\" value=\"%@\"></param><param name=\"wmode\" value=\"transparent\"></param><embed src=\"%@\" type=\"application/x-shockwave-flash\" wmode=\"transparent\" width=\"320\" height=\"480\"></embed></object></div></body></html>",videoUrl,videoUrl] ; 

[webView loadHTMLString:htmlString baseURL:[NSURL URLWithString:@"http://www.youtube.com"]]; 

//[window addSubview:webView]; 
[webView release]; 

[super viewDidLoad]; 
// Do any additional setup after loading the view. 
} 

當用戶按下此的UIButton應該開始播放嵌入YouTube視頻

UIButton *videoButton = [UIButton buttonWithType:UIButtonTypeCustom]; 
[videoButton addTarget:self action:@selector(VideoAction:) forControlEvents:UIControlEventTouchUpInside]; 
videoButton.frame = CGRectMake(0, 0, 40, 40); 
UIImage *icn = [UIImage imageNamed:@"Video_icon.png"]; 
[videoButton setImage:icn forState:UIControlStateNormal]; 
UIBarButtonItem *video = [[UIBarButtonItem alloc] initWithCustomView:videoButton]; 

我怎麼能播放YouTube視頻。

感謝您的幫助。

+0

當用戶按下'videoButton'或'視頻barButton'? – 2012-08-12 13:39:08

+0

VideoButton這是UIToolbar上的UIBarButtonItem – user1452248 2012-08-12 13:47:02

+0

我很抱歉,我沒有閱讀代碼。 – 2012-08-12 13:50:24

回答

1

你爲什麼不試試這個:

  [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.youtube.com/watch?v=oHg5SJYRHA0"]]] 
      [self.view addSubview:webView]; 
+0

我應該嘗試在視頻操作方法或視圖中加載方法。 – user1452248 2012-08-13 17:22:29

+0

把這裏面的視頻操作方法。在視頻完成後,將視頻從視圖中移除。 – 2012-08-14 06:35:09

相關問題