primulaveris primulaveris - 1 month ago 35
iOS Question

Play YouTube video full screen

I want to use YouTube Helper to play YouTube videos in my app. I want to display the YTPlayerView in a table view cell, and when the video is tapped, I want it to start playing in full screen mode.
However, when I tried out the YouTube helper it plays the video inline and doesn't expand to fullscreen.
Is there any way of getting the video to play full screen immediately with YouTube helper?


Actually this is pretty easy. Here is the code for showing YTPlayerView in a table cell. Tap the YouTube thumbnail to play in full screen.

Create a custom table view cell. In Interface Builder, drag a view into your cell, change the class to YTPlayerView and hook it up to the playerView property of your cell.

#import <UIKit/UIKit.h>
#import "YTPlayerView.h"
@interface VideoCellTableViewCell : UITableViewCell
@property (nonatomic, strong) IBOutlet YTPlayerView *playerView;
@property (assign) BOOL isLoaded; 

In your view controller:

- (UITableViewCell *)tableView:(UITableView *)tableView    cellForRowAtIndexPath:(NSIndexPath *)indexPath
    VideoCellTableViewCell *cell = (VideoCellTableViewCell *) [tableView dequeueReusableCellWithIdentifier:@"VideoCell" forIndexPath:indexPath];
    [cell.playerView stopVideo];
    if (!cell.isLoaded) {
       [cell.playerView loadWithVideoId:@"your video ID"];
       cell.isLoaded = YES;
     else { 
         // avoid reloading the player view, use cueVideoById instead
         [cell.playerView cueVideoById:@"your video ID" startSeconds:0 suggestedQuality:kYTPlaybackQualityDefault];
return cell;