YTPlayerView youtube-ios-player-helper暂停不起作用

时间:2021-08-24 18:56:42

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.

我在使用Youtube youtube-ios-player-helper库时遇到了麻烦。我可以将视频加载到播放器中并播放但如果我点击暂停,视频会停止几秒钟,然后再次开始播放。

The incredibly simple UIViewController code to start the video is:

用于启动视频的非常简单的UIViewController代码是:

- (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:

我使用NSLog检测了didChangeToState委托方法,如下所示:

- (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:

在Xcode日志中,当我点击“播放”开始视频播放时,我看到:

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.

值4似乎没有在YTPlayerView.m中定义。当视频实际开始播放时,我会看到预期的已开始播放日志消息。

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.

当我点击“暂停”时,我在日志中看不到任何内容(没有触发didChangeToState事件 - 我期望的事件是每个YTPlayerView文档的kYTPlayerStatePaused)。然而几秒钟后,视频再次开始播放,然后我看到两个连续的已开始播放日志消息(kYTPlayerStatePlaying事件)。每当我按'暂停'试图暂停视频时,它会暂停几秒钟(没有kYTPlayerStatePaused事件),但随后它再次开始播放,我看到已开始播放日志消息。

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

有人看到这个吗?谁知道从哪里去?这是Xcode 6.2,构建目标是iOS 8.0。

1 个解决方案

#1


9  

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

我在Github问题跟踪器中找到了解决方案。对不起,我想我在之前的研究中错过了。

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

描述的修复程序在这里:https://github.com/youtube/youtube-ios-player-helper/issues/86

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

在YTPlayerView-iframe-player.html中,删除或评论下面的代码。

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.

还有另一个建议的修复程序完全取代了YTPlayerView-iframe-player.html文件,但上面似乎对我有用。我担心谷歌自己的这个基本功能代码从根本上被打破了。

#1


9  

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

我在Github问题跟踪器中找到了解决方案。对不起,我想我在之前的研究中错过了。

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

描述的修复程序在这里:https://github.com/youtube/youtube-ios-player-helper/issues/86

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

在YTPlayerView-iframe-player.html中,删除或评论下面的代码。

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.

还有另一个建议的修复程序完全取代了YTPlayerView-iframe-player.html文件,但上面似乎对我有用。我担心谷歌自己的这个基本功能代码从根本上被打破了。