views:

492

answers:

1

I'm a newbie to iPhone development and just started on developing an application that contains a UITableView where each cell consisting of youtube video thumbnails in the form of webviews. For embedding YouTube Player on iPhone, I have used the follwing piece of code.

- (void)embedYouTube:(NSString*)url frame:(CGRect)frame {  
 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, frame.size.width, frame.size.height];  
if(videoView == nil) {  
  videoView = [[UIWebView alloc] initWithFrame:frame];  
  [self.view addSubview:videoView];  
}  
[videoView loadHTMLString:html baseURL:nil];

}

Now that I can see the thumbnail on the tableviewcell and once I tap on the thumbnail, YouTube player opens and play the movie.

My thumbnail occupies only a small portion of the cell and the rest of the area of the cell contains some text descriptions. My problem is that I must tap exactly on the thumbnail for the movie to play. If I tap somewhere else on the cell then it wouldn't play because my thumbnail doesn't extend all over the cell.

Isn't there a way to make the movie to play in didSelectRowAtIndexPath? I have seen some chaps suggest using Javascript but nobody seem to have an idea on the correct way of using it for this problem.

Highly appreciate it if anybody can help.

+1  A: 

I suggest you to take a look at YouTube APIs and try to figure it out what is your real problem. but another good link is How To Play YouTube Videos Within an Application. Hope I'm helping you.

Nathan Campos
thanx Nathan for your quick reply. Actually I have gone through the link that you posted couple of days back. Let me be clear here. I have no problem in playing the video. All I need is to make it play when I tap elsewhere on the cell. Even in the youtube API blog, nobody seem to have answered that.
suranga
@suranga: you should edit your question and make that clearer so that people quickly know what your problem is
Spoike
@suranga: take a look at that second link please.
Nathan Campos
@Nathan: This blog doesn't seem to solve my problem. I may be able to direcly fetch the Youtube URL and play the movie. But it's gonna quit my application and start iPhone youtube app which is not I want. I thought of using MPMovie player also but it doesn't support youtube vids.
suranga