在iOS8上(重新)缓冲时,Youtube didChangeToState不会被触发

时间:2016-01-26 10:13:55

标签: ios iframe youtube-api

我想检测在使用适用于iOS的YouTube库(在iFrame上构建)播放YouTube视频时,何时进行重新缓冲(即在视频开始播放时发生缓冲)。我已按照说明(https://developers.google.com/youtube/v3/guides/ios_youtube_helper)了解如何配置和启动视频。在运行iOS 9的iPhone上,一切都按预期工作,但是当在iOS 8的iPhone上运行相同的代码时,方法didChangeToState的状态为YTPlayerState.Buffering永远不会被调用(在调用YTPlayerState.Playing之后),即使很明显视频有时是回避。

报告的大致相同的行为存在一个问题,区别在于iFrame库直接在UIWebView中使用:https://code.google.com/p/gdata-issues/issues/detail?id=6680
我的猜测是我的问题与这个问题有关。

有没有办法在iOS 8上使用YouTube的iOS库检测重新缓冲?

我使用以下代码来检测重新缓冲:

class ViewController: UIViewController {

    @IBOutlet weak var playerView: YTPlayerView!

    override func viewDidLoad() {
        super.viewDidLoad()

        print("View did load")
        playerView.delegate = self

        let playerVars: [NSObject: AnyObject] = ["playsinline":1] // Plays the video in the UIView instead of fullscreen. To programmatically control playback.
        playerView.loadWithVideoId("M7lc1UVf-VE", playerVars: playerVars)
    }
}

extension ViewController: YTPlayerViewDelegate {

    // MARK: YTPlayerViewDelegate

    func playerView(playerView: YTPlayerView!, didChangeToState state: YTPlayerState) {
        switch state {
        case .Buffering:
            print("Buffering")
            break
        case .Ended:
            print("Ended")
            break
        case .Paused:
            print("Paused")
            break
        case .Playing:
            print("Playing")
            break
        case .Queued:
            print("Queued")
            break
        case .Unknown:
            print("Unknown")
            break
        case .Unstarted:
            print("Unstarted")
            break
        }
    }

    func playerView(playerView: YTPlayerView!, receivedError error: YTPlayerError) {
        print("Error: " + "\(error)")
    }

    func playerViewDidBecomeReady(playerView: YTPlayerView!) {
        print("Player did become ready")
        self.playerView!.playVideo()
    }
}

在带宽较低的网络上,我从带有iOS 9的iPhone获得以下输出(以斜体重新缓冲):
视图确实加载了 玩家确实准备好了 缓冲

缓冲




缓冲

已结束

另一方面,在iOS 8上,输出仅(与带宽无关):
视图确实加载了 玩家确实准备好了 缓冲

结束

0 个答案:

没有答案