Aralekk / simple360player_iOS

Simple 360 Video player for iOS using SceneKit
161 stars 22 forks source link

AVPlayer Looping #4

Closed weberbry closed 8 years ago

weberbry commented 8 years ago

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 commented 8 years ago

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 commented 8 years ago

Hi ,

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

Arthur

Aralekk commented 8 years ago

Thanks @kosso for the video loop !