我在應用程序中播放You Tube視頻並試圖檢測視頻何時暫停或結束?我在.m文件中找到了kYTPlayerState
函數,但無法將其用於Swift。下面是我....如何使用Swift檢測YTPlayerState.Ended?
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");
break;
default:
break;
}
}
和.....
if playerView(player , didChangeToState: YTPlayerState.Ended)
{
/// Do Something....
}
....我放在viewDidLoad中()。我也回到了我的if語句中的錯誤Type "()" does not conform to protocol "Boolean Type"
。如果你知道如何解決這個問題,或者如果我要離開一些東西,請幫忙。
我初始化該視圖中的球員@IBOutlet var player: YTPlayerView!
嘿查爾斯對我的回答有幫助嗎?如果您有任何其他問題,請告訴我。 – JAL
@JAL是的,它效果很好。我想我感到困惑,並試圖在viewWillLoad中實現'if state'語句,因爲我已經使用其他事件/監視協議來完成此操作。 –
太棒了,很高興聽到它!隨時將我的答案標記爲已接受,以向其他用戶展示我的答案爲您提供幫助的相同問題。如果您有任何其他問題,請不要猶豫,在這裏或在另一個問題跟進我。快樂的編碼! – JAL