我希望我的YouTubePlayer状态更改我的 View Controller 中的公共(public)变量。我在使用YTPlayer委托(delegate)功能和开关时遇到了麻烦。这是我的var ...
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.Ended或YTPlayerState.Paused的状态,以将空字符串的值更改为“Ended / Paused”?
最佳答案
我想您可以将print("Paused")
和print("Ended")
替换为ytps = "Paused"
和ytps = "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
}
}