在iOS中检测以YTPlayer View结尾的歌曲

时间:2019-07-30 12:18:43

标签: ios youtubeplayer

我使用YTPlayer View通过videoID播放歌曲,现在我想检测当前歌曲的结束状态,我使用了一个委托但它没有捕获它。如何检测歌曲何时结束,以便我可以播放下一首歌。这是我的代码,

func playerView(playerView: YTPlayerView!, didChangeToState state: YTPlayerState)
{
    switch (state) {
    case YTPlayerState.playing:
        print("Started playback");
        break;
    case YTPlayerState.paused:
        print("Paused playback");
        break;
    case YTPlayerState.ended:
        print("Ended playback");
        self.selectedIndex = selectedIndex + 1

        let videoId = playListArray[selectedIndex].videoId
        self.songView.load(withVideoId: videoId!, playerVars: playerVars)
        break;
    default:
        break;
    }
}

也使用了此委托人YTPlayerViewDelegate。但是它并没有进入最终状态。

0 个答案:

没有答案