如何对Swift中的开关进行编程以读取YouTubePlayerState



我希望我的YouTubePlayer State更改视图控制器中的公共变量。YTPlayer代理功能和开关出现问题。这是我的变体…

var ytps = String! 

这是youtube的状态函数。。。

func playerView(player: YTPlayerView!, didChangeToState state: YTPlayerState)
    {
        switch (state)
        {
        case YTPlayerState.Ended:
            // handle ended state
            print("Ended")
            break;
        case YTPlayerState.Paused:
            // handle paused state
            print("Paused")
            break;
        default:
            break;
        }
    }

如何获取YTPlayerState.Endd或YTPlayerState.Paused的状态以将空字符串的值更改为"Ended/Paused"?

我想您可以用ytps = "Paused"ytps = "Ended"替换print("Paused")print("Ended")。完整示例:

var ytps = String()
func playerView(player: YTPlayerView!, didChangeToState state: YTPlayerState) {
    switch state {
        case YTPlayerState.Ended:
            ytps = "Ended"
            break
        case YTPlayerState.Paused:
            ytps = "Paused"
            break
        default:
            break
    }
}

相关内容

  • 没有找到相关文章

最新更新