Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

YTPlayerView youtube-ios-player-helper pause not working

I'm having trouble with the Youtube youtube-ios-player-helper library. I can load a video into the player and it plays but if I tap pause the video stops for a few seconds and then starts playing again.

The incredibly simple UIViewController code to start the video is:

- (void)viewDidLoad {
    [super viewDidLoad];
    self.player = [[YTPlayerView alloc] initWithFrame:CGRectMake(X, Y, WIDTH, HEIGHT)];

    self.player.delegate = self;
    [self.view addSubview:self.player];
    [self.player loadWithVideoId:@"bQCjOm4p5jM"];

}

I instrumented the didChangeToState delegate method with NSLog as follows:

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

In the Xcode log, when I tap 'play' to start the video playing, I see:

didChangeToState 4

The value 4 does not appear to be defined in YTPlayerView.m. When the video actually starts playing I see the expected Started playback log message.

When I tap 'pause', I don't see anything in the log (no didChangeToState event triggered - the event I'd expect would be kYTPlayerStatePaused per the YTPlayerView docs). However a few seconds later, the video starts playing again, and then I see two consecutive Started playback log messages (kYTPlayerStatePlaying events). Every time I press 'pause' to try to pause the video, it pauses for a few seconds (with no kYTPlayerStatePaused event), but then it starts playing again and I see Started playback log messages.

Anyone else seeing this? Anyone know where to go from here? This is Xcode 6.2 and build target is iOS 8.0.

like image 407
mrblog Avatar asked Mar 26 '15 23:03

mrblog


1 Answers

I found a solution here in the Github issue tracker for the code. Sorry, I guess I missed that in my earlier researching.

The fix described is here: https://github.com/youtube/youtube-ios-player-helper/issues/86

In YTPlayerView-iframe-player.html, remove or comment below code.

window.setInterval(forcePlay, 5000);

There's another suggested fix that completely replaces the YTPlayerView-iframe-player.html file but the above seems to have worked for me. It concerns me that Google's own code for this basic function is so fundamentally broken.

like image 81
mrblog Avatar answered Nov 06 '22 04:11

mrblog