Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AVPlayer Looping #4

Closed
weberbry opened this issue Feb 1, 2016 · 3 comments
Closed

AVPlayer Looping #4

weberbry opened this issue Feb 1, 2016 · 3 comments

Comments

@weberbry
Copy link

weberbry commented Feb 1, 2016

I am trying to take action when the video finishes. To do this I subscribed to the AVPlayerItemDidPlayToEndTimeNotification notification. By doing this I noticed that this notification gets called repeatedly after the video finishes, multiple times a second.

I looked into the issue further by setting up KVO on the "rate" property of the player and noticed that after the videos finishes the rate values switches between 0 and 1 repeatedly, multiple times per second.

This explains why AVPlayerItemDidPlayToEndTimeNotification is getting calls so much but does not explain why the rate keeps toggling. The actual on screen video is frozen at the last frame and does not seen to be impacted.

The only thing that breaks this loop is calling videoSpriteKitNode!.pause(). Even this approach is not ideal because you still get a few AVPlayerItemDidPlayToEndTimeNotification notifications before you have a chance to call videoSpriteKitNode!.pause().

@kosso
Copy link

kosso commented Feb 22, 2016

I managed to get a video looping using

        NSNotificationCenter.defaultCenter().addObserver(self,
            selector: "loopVideo",
            name: AVPlayerItemDidPlayToEndTimeNotification,
            object: player?.currentItem
        )

and

func loopVideo()  {

        player!.pause()

        let seconds : Int64 = 0
        let preferredTimeScale : Int32 = 1
        let seekTime : CMTime = CMTimeMake(seconds, preferredTimeScale)
        player!.seekToTime(seekTime)
        player!.play()
    }

But after looping a few times, I get some repeated memory warnings, then the app crashes.

@Aralekk
Copy link
Owner

Aralekk commented Feb 22, 2016

Hi ,

Yes there is a memory issue with SKVideoNode leaking memory :/ I'll report you to this opened issue and NickAtGit response: #2
If I reproduce it I'll file a radar bug report to Apple.

Arthur

@Aralekk
Copy link
Owner

Aralekk commented Feb 22, 2016

Thanks @kosso for the video loop !

@Aralekk Aralekk closed this as completed Feb 22, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants