Advertise here




Advertise here

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Google Sign In with OpenID

How to play youtube movie?

Maor-SMaor-S Posts: 2New Users
edited March 2012 in iPhone SDK Development
how can I play youtube movie?
Thanks
Post edited by Maor-S on

Replies

  • echtraechtra Posts: 5New Users
    edited October 2010
    Try to use imobilecinema or Take a look at this instructional post. I think it can help you.

    How to Watch YouTube Videos on Your iPhone | eHow.com

    I hope this can help.
  • Maor-SMaor-S Posts: 2New Users
    edited October 2010
    echtra wrote: »
    Try to use imobilecinema or Take a look at this instructional post. I think it can help you.

    How to Watch YouTube Videos on Your iPhone | eHow.com

    I hope this can help.

    Ho no..
    I want to play Youtube inside my app.
  • listingboatlistingboat Posts: 55Registered Users @
    edited October 2010
    Maor-S wrote: »
    Ho no..
    I want to play Youtube inside my app.

    It's a little tricky, but I got this to work:

    What you need to do is put some custom HTML and embed the video in a UIWebView. I create a small UIWebView behind one of my UILabels in my view so the user doesn't really see it. For the code to play the video when the user clicks something like a View Video button, I use this:
    			// This is a youtube video.  Put up an invisible UIWebView 
    			if (youTubeWebView == nil) {
    				youTubeWebView = [[UIWebView alloc] initWithFrame:CGRectMake(5.0, 5.0, 2.0, 2.0)];
    				youTubeWebView.scalesPageToFit = YES;
    				youTubeWebView.delegate = self;
    				
    				[self.view insertSubview:youTubeWebView atIndex:0];	
    			}
    			NSString* embedHTML = @""
    			"<html><head>"
    			"<style type=\"text/css\">"
    			"body {" 
    			"background-color: transparent;"
    			"color: white;"
    			"}" 
    			"</style>"
    			"</head><body style=\"margin:0\">" 
    			"<object width=\"%0.0f\" height=\"%0.0f\"><param name=\"movie\" value=\"%@&autoplay=1\">"
    			"</param><embed src=\"%@&autoplay=1\" type=\"application/x-shockwave-flash\" width=\"%0.0f\" height=\"%0.0f\"></embed></object>"
    			"</body></html>";  
    			NSString *html = [NSString stringWithFormat:embedHTML,
    							  youTubeWebView.frame.size.width, 
    							  youTubeWebView.frame.size.height,
    							  thisFilm.trailerURL, 
    							  thisFilm.trailerURL,
    							  youTubeWebView.frame.size.width, 
    							  youTubeWebView.frame.size.height];
    			[youTubeWebView loadHTMLString:html baseURL:nil];
    

    Then, you need the following code inside your controller to capture the UIWebView delegate call that the load finished:
    - (void)webViewDidFinishLoad:(UIWebView *)_webView {
    	UIButton *b = [self findButtonInView:_webView];
    	[b sendActionsForControlEvents:UIControlEventTouchUpInside];
    }
    

    Lastly, implement the findButtonInView method. This method recurses through the UIWebViews subviews looking for the button the user needs to click to start the video. This is so you can have the video auto play without the user having to press or see the embedded youtube view.
    - (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;
    }
    
    
  • zanquezanque Posts: 7New Users
    edited March 2012
    Hello

    i tried this method with iPhone and it worked fine.
    but its not working with iPad .. the video plays and you can hear the sound of the video but the youtube player is not showing.

    any thought why ?
  • listingboatlistingboat Posts: 55Registered Users @
    edited March 2012
    zanque wrote: »
    Hello

    i tried this method with iPhone and it worked fine.
    but its not working with iPad .. the video plays and you can hear the sound of the video but the youtube player is not showing.

    any thought why ?

    Hmm, I never tried this on an iPad, so not sure what would be happening here. Sorry.
Sign In or Register to comment.