gpt4 book ai didi

swift - 如何在 Swift 中编写一个开关来读取 YouTubePlayerState?

转载 作者:行者123 更新时间:2023-11-30 13:26:51 26 4
gpt4 key购买 nike

我希望 YouTubePlayer State 更改 View Controller 中的公共(public)变量。我在使用 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.Ended 或 YTPlayerState.Paused 的状态以将空字符串的值更改为“Ended/Paused”?

最佳答案

我想你可以将 print("Paused")print("Ended") 替换为 ytps = "Paused" 并且ytps =“已结束”。完整示例:

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
}
}

关于swift - 如何在 Swift 中编写一个开关来读取 YouTubePlayerState?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37083887/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com