2011-10-24 14 views
1

私のアプリケーションでYouTubeビデオを横長モードで直接再生したいですか?私はこのようなコードを書いていますが、運はありません:アプリケーションでYouTubeビデオを再生する

- (void)viewDidLoad { 
[super viewDidLoad]; 
NSMutableDictionary *data = [[NSMutableDictionary alloc] init]; 
data = [[HBAppDelegate getGlobalInfo] valueForKey:@"tmp_page_data"]; 
NSString *url = [[NSString alloc] init]; 
url = [data valueForKey:@"trailer_url"]; 
videoView = [[UIWebView alloc] init]; 
[self embedYouTube:url frame:CGRectMake(0, 0,320, 240)]; 
} 
- (void)embedYouTube:(NSString *)urlString frame:(CGRect)frame { 

NSString *htmlString [email protected]"<html><head>" 
"<meta name = \"viewport\" content = \"initial-scale = 1.0, user-scalable = no, width = 212\"/></head>" 
"<body style=\"background:#FFFFF;margin-top:20px;margin-left:0px\">" 
"<div><object width=\"320\" height=\"240\">" 
"<param name=\"wmode\" value=\"transparent\"></param>" 
"<embed src=\"%@\"" 
"type=\"application/x-shockwave-flash\" wmode=\"transparent\" width=\"320\" height=\"240\"></embed>" 
"</object></div></body></html>"; 

NSString *html = [NSString stringWithFormat:htmlString, urlString, frame.size.width, frame.size.height]; 
[videoView setFrame:frame]; 
videoView.delegate=self; 
[videoView loadHTMLString:html baseURL:nil];  
} 
- (void)webViewDidFinishLoad:(UIWebView *)_webView { 
    UIButton *b = [self findButtonInView:_webView]; 
    [b sendActionsForControlEvents:UIControlEventTouchUpInside]; 
} 

- (UIButton *)findButtonInView:(UIView *)view { 
    UIButton *button = nil; 

    if ([view isMemberOfClass:[UIButton class]]) { 
     return (UIButton *)view; 
    } 

    if (view.subviews && [view.subviews count] > 0) { 
     for (UIView *subview in view.subviews) { 
      button = [self findButtonInView:subview]; 
      if (button) return button; 
     } 
    } 
    return button; 
} 

答えて

3
NSString *embedHTML = @"\ 
<html><head>\ 
<style type=\"text/css\">\ 
body {\ 
background-color:white;\ 
color: Black;\ 
}\ 
</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, urlString, frame.size.width, frame.size.height]; 
videoView = [[UIWebView alloc] initWithFrame:frame]; 
[videoView loadHTMLString:html baseURL:nil]; 
[self.view addSubview:videoView]; 
関連する問題