I have an SKVideoNode, like so -
let path = "videoURL";
let url = NSURL(string: path);
let asset = AVURLAsset(URL: url!,options: nil);
let playerItem = AVPlayerItem(asset: asset);
let playerThree = AVPlayer(playerItem: playerItem);
let videoNode = SKVideoNode(AVPlayer: playerThree);
Which I want to pause on a button press, the button looks like this -
var isPausedThreeSixty : Bool = false;
@IBAction func threesixty(sender: AnyObject){
if (videoPlayer == 1) { // check if video player is the 360 videoplayer
if(isPausedThreeSixty == false){ //check if video is paused, if not pause video on click
videoNode?.pause(); // pause video node
print("pause player");
isPausedThreeSixty == true;
}else{ //if app runs else, video is paused, proceed to unpause.
videoNode?.play();
print("play player");
isPausedThreeSixty = false;
}
}
}
My code does print the pause player
and play player
but it just won't pause the video, I've also read that I should pause the AVPlayer instead, but when calling playerThree.pause();
the video isn't being paused either.
see - How do I control playback of a video in an iOS Sprite Kit SKVideoNode?
and
AVPlayer play SKVideoNode video ,I just can not control the playback
Why are multiple SO answers saying that calling .pause
and .play
on the SKVideoNode works, even though when implementing it, it doesn't actually work.
After pausing this video I want to be able to swap to a new video player, I've got that working.. it's just that I can't delete or pause this video player.
see - https://forums.developer.apple.com/thread/28470 according to this post AVPlayer rate is being overwritten, and thus a SKVideoNode cannot be paused.
I had to pause the AVPlayerItem so -
Did the trick.