I'm playing You Tube videos in my app and trying to detect when a video is paused or ended? I've found the kYTPlayerState
function in the .m file, but having trouble converting it's use to Swift. Here is what I have....
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;
}
}
and .....
if playerView(player , didChangeToState: YTPlayerState.Ended)
{
/// Do Something....
}
....which I place in ViewDidLoad(). I'm also getting back the error on my if statement that says Type "()" does not conform to protocol "Boolean Type"
. If you know how to fix this, or if I'm leaving something out please help.
I'm initializing the player in this view with @IBOutlet var player: YTPlayerView!