How to play YouTube movie on iPhone app when using UITableViewCell?

I am new to iPhone development and have just started developing an application containing a UITableView where each cell, consisting of thumbnails of YouTube videos, is in the form of web views. To implement YouTube Player on iPhone, I used the following 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 see a thumbnail on a tableviewcell, and as soon as I click on the thumbnail, the YouTube player opens and plays the movie.

My thumbnail occupies only a small part of the cell, and the rest of the cell contains some textual descriptions. My problem is that I have to click exactly on the thumbnail for the movie to play. If I touch another place in the cell, it will not play because my thumbnail does not spread throughout the cell.

didSelectRowAtIndexPath? , Javascript, , , , .

, - .

+5
2
+3

, , :

//get your UIWebview in tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
//...

videoView.mediaPlaybackRequiresUserAction = NO;
[videoView loadHTMLString:[self generateHtmlEmbedYouTube] baseURL:nil];

Documentation

mediaPlaybackRequiresUserAction

, HTML5 .

, UIWebView.

0

All Articles