Saturday, April 18, 2015

iOS Playing Youtube video.

Playing youtube video is easy and an application can play this using the help component that is provided. 
More details are at the links mentioned in References: 

The code to integrate this is as follows 

Firs of all, download the github repository files and take the YTPlayerView.h & YTPlayerView.m files
Also, take the asset folder that contains the HTML file that is loaded by this YTPlayerView class 
Make sure it is included in the bundle, otherwise, need to do a work around to load the file file resource instead of the build that the class by default looking for. 

Now, below are the steps to add the player and start playing it. 

#import “YTPlayerView.h”
@property(nonatomic, strong) IBOutlet YTPlayerView *playerView;

[self.playerView loadWithVideoId:@"M7lc1UVf-VE"];


There are a few delegates like below. 

@interface ViewController : UIViewController
- (void)playerView:(YTPlayerView *)playerView didChangeToState:(YTPlayerState)state {
    switch (state) {
        case kYTPlayerStatePlaying:
            NSLog(@"Started playback");
            break;
        case kYTPlayerStatePaused:
            NSLog(@"Paused playback");
            break;
        default:
            break;
    }
}

- (void)playerViewDidBecomeReady:(YTPlayerView *)playerView;
- (void)playerView:(YTPlayerView *)playerView didChangeToState:(YTPlayerState)state;
- (void)playerView:(YTPlayerView *)playerView didChangeToQuality:(YTPlaybackQuality)quality;
- (void)playerView:(YTPlayerView *)playerView receivedError:(YTPlayerError)error;


There are quite some bugs in this class it looks like. Did some modification in the class for few tests. 

References: 

No comments:

Post a Comment