Post

Replies

Boosts

Views

Activity

Reply to AVPlayerItem step(byCount:) callback or notification
Quick update here. First of all, thanks @Dirk-FU - I was thinking about that but held it for now as the app supports iOS 15+ where the AVSampleCursor is available from iOS 16.0+ as from the docs so I needed to find a common solution for all supported versions. So... After playing around I found what was causing my issue as that same code worked for me just fine not long ago. The notification never gets fired simply because the player item's canStepForward and/or canStepBackward are false thus the step(byCount:) doesn't move the time anywhere. So all works fine. Not how I needed it but correct. Furthermore in my case the item cannot step back or forth simply because at some stage I switched to an AVQueuePlayer as I needed to be able to loop the video. Since the previous version used an AVPlayer instead and I was using a local variable for the PlayerItem (aka my custom AVPlayerItem) I was calling the method on that variable but it might not be the one currently used by the player thus the canStepForward and/or canStepBackward are false. Simply said an oversight on my side. So the final change in my controller's code lead to all working fine again: @discardableResult func step(_ direction: Direction) async -> Bool { guard let playerItem = player.currentItem as? PlayerItem else { return false } let currentTime = playerItem.currentTime() pause() switch direction { case .back: guard currentTime > .zero else { return false } await playerItem.step(by: -1) case .forward: guard currentTime < videoDuration else { return false } await playerItem.step(by: 1) } return true }
Jan ’25