Search code examples
iphoneobjective-ciosios4youtube-api

How to play videos from youtube, metacafe etc in a native iphone app?


I get a feed which consists of a URL pointing to the videos from sites like youtube, metacafe etc.

I found this post suggesting how to use UIWebView to load the video into the app. However I don't want the video to play in full screen mode. I want it to play in the frame I have allocated for it.

  1. How do I make the youtube video which is loaded by embedding html into the uiwebview play in the frame allocated to it and not in full screen mode?

  2. How do we play videos from sites like metacafe and comedy central and other sites where url doesn't point to a file but instead loads a player if pasted on browser.

  3. Are there any applications which have achieved to play the same as a native iphone app?

Any help in this regards would be greatly helpful.

EDIT: I want to know how do we play a video from the url say - http://www.dailymotion.com/swf/video/xe1l96

I would like to know how to play the video in the webview itself. I want to use the space around it to display other information. Currently it forces full screen mode.

Safari is able to play dailymotion and vimeo videos by lauching the quicktime player. So I would like to know how to redirect to play the videos using quicktime player.

How do I play videos from youtube and metacafec in a native iphone app?


Solution

  • - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
         UIWebView  *wbView = (UIWebView *)[cell.contentView viewWithTag:1];
         NSString *embedHTML = @"\
        <html><head>\
        <style type=\"text/css\">\
        body {\
        background-color: transparent;\
        color: white;\
        }\
        </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,url, 64.0, 64.0];
        [wbView loadHTMLString:html baseURL:nil];
    
    
    
    }
     "url" is the youtube video url
    
    
    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
        UITableViewCell *cell = [category_table cellForRowAtIndexPath:indexPath];
    
        UIWebView  *wbView = (UIWebView *)[cell.contentView viewWithTag:1];
        UIButton *btn = [self findButtonInView:wbView];
        [btn sendActionsForControlEvents:UIControlEventTouchUpInside];
    
    }
    
    
    // detecting the play button on the you tube video thumbnail
    
    - (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;
    }
    
    
    - (void)webViewDidFinishLoad:(UIWebView *)_webView {
        UIButton *button = [self findButtonInView:_webView];
        [button sendActionsForControlEvents:UIControlEventTouchUpInside];
    }
    

    Basically, i had to show thumbnails in table cell