6

How can I get a YouTube-video in a UITableViewCell, and how do I handle the Done-button of the UIWebView playing the video?

I have embedded the video in a view, but like on the image. And I want this Done-button in this image:

Screenshot

I want to open another screen when I return to the view, not the previous view.

-(void)viewDidLoad {
    [super viewDidLoad];
    videoURL = [[NSString alloc]init];
    videoURL =@"http://www.youtube.com/watch?v=aE2b75FFZPI";
    [self embedYouTube:videoURL frame:CGRectMake(10, 85, 300, 180)];
}


- (void)embedYouTube:(NSString*)url frame:(CGRect)frame {  
    NSString* embedHTML = @"\ <html><head>\ <style type=\"text/css\">\ body {\ background-color: transparent;\ color: red;\ }\ </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, frame.size.width, frame.size.height];  
    if (videoView == nil) {  
        videoView = [[UIWebView alloc] initWithFrame:frame];  
        [self.view addSubview:videoView];  
        NSLog(@"html%@",html);
    }  

    [videoView loadHTMLString:html baseURL:nil];  
}

I need some help with this. I did a search, but I didn't get anything.

Emil
  • 7,220
  • 17
  • 76
  • 135
Harish
  • 544
  • 3
  • 17
  • Did I understand You correctly - You want to your tableview cells represent each youtube video? fullscreen? why do you want to do that? – Guntis Treulands May 14 '12 at 12:14
  • I done with the Table And want know how to handle the youtube video done button ? – Harish May 16 '12 at 04:25
  • Done button is not showing? Or just not responding? Did you tried Done button notifications? http://stackoverflow.com/a/8228490/894671 – Guntis Treulands May 16 '12 at 08:18
  • @GuntisTreulands actually i have play youtube video like [self.webView loadHTMLString:content baseURL:baseURL]; it get appered on the view when click on that it play at time Done come look above image i want to handle that – Harish May 18 '12 at 06:41
  • @GuntisTreulands is this any to send the notification that [videoView loadHTMLString:html baseURL:nil] is load on the screen – Harish May 18 '12 at 06:51
  • actually i take video from youtube for this i use the embedded method but when play video it get out my application and when it get finish it get back automatically to previous page of application And it behave same when i click on the "DONE BUTTON" and I want handle that when it get finish ,I want to open other screen not previous screen And in the same with doneBUTTOn click – Harish May 18 '12 at 07:03
  • The done button is handled inside the YouTube application, which is what gets called when you tap the UIWebView with your youtube clip embedded in it. I have never had to handle the done button separately, it has always worked by default. – ThisDarkTao May 22 '12 at 09:37

2 Answers2

0

Since this has gone unanswered for a bit, I thought I might offer a suggestion. The end result I believe is the same as what you are looking for but the path to get there is a little different.

So from my understanding, you want a UITableView controller to display a list of YouTube videos that play when you click on them. Here is how I handled this scenario in one of my applications.

  1. You need to get an RSS feed of videos you want in your list. That's pretty easy... if it's for a user the format is http://www.youtube.com/rss/user/{USERNAME}/videos.rss
  2. So from there you need to parse the RSS feed into a list of objects that have a title, description, thumbnail, and link to the video. All of this is provided in the RSS and I used NSXMLParser to do the work.
  3. Once you have a nice list of value objects to work with, all you need to do is have the table fire off a MPMoviePlayerViewController and pass it the URL to play the movie.

didSelectRowAtIndexPath Implementation

- (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    /** self.items is just a mutable array of video objects that is the underlying 
        datasource for the table.  The Video object is just a simple value object 
        I created myself */
    Video *video = [self.items objectAtIndex:[indexPath row]];

    MPMoviePlayerViewController *mp = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL URLWithString:video.video]];

    [self presentMoviePlayerViewControllerAnimated:mp];

    [mp release];
}

Here is what the interface for my Video class looks like

@interface Video : NSManagedObject {

@property (nonatomic, retain) NSString * title;
@property (nonatomic, retain) NSString * link;
@property (nonatomic, retain) NSString * comments;
@property (nonatomic, retain) NSString * thumbnail;
@property (nonatomic, retain) NSString * pubDate;
@property (nonatomic, retain) NSString * video;
@property (nonatomic, retain) NSString * guid;
@property (nonatomic, retain) NSString * desc;

@end

That's pretty much it, a nice easy way to display YouTube videos in a UITableViewController. I won't get into the XML parsing, there is a ton of documentation out there on how to do that. I just did a quick google and this blog actually gets into the nuts and bolts of what I'm talking about:

http://useyourloaf.com/blog/2010/10/16/parsing-an-rss-feed-using-nsxmlparser.html

Hope this gets you going. I know this doesn't address putting the markup in a WebView, but I think you'll find this way a little more intuitive and since there haven't been many responses... hopefully it will get you up and running.

jerrylroberts
  • 3,419
  • 23
  • 22
0

What your are looking to do involves messing with the mediaplayer used by UIWebView. This can be done by monitoring uiviewanimation notifications and then going through a bunch of subviews but it will involve using private methods and therefore is not recommended especially since the way the private media player behaves changes with each os. I would recommend using jerrylroberts answer and getting direct links to the YouTube videos.

eni9889
  • 21
  • 4