How to observe AVKit (AVPlayer) player rate >= 2.0?

Question #1 How do you determine what the player rate is, after command-clicking the fast-forward control?

Question #2 Is there something that needs to be done to keep the audio when manually adjusting the playback rate for 2.0+

Property observing appears to work only for rates below 2.0

Background I am using custom controls (slider and stepper) that are available for the user to manage the speed of playback and keeping both in sync. I am keeping them in sync by obtaining the player rate, using a property observer. Changing the custom control adjusts the play rate and changing the AVKit provided controls changes the custom controls. This works as expected until I command-click the fast-forward control. The property observer reports a play rate of 0, which should mean it is stopped but it is clearly moving forward at a high rate. If I programmatically change the play rate (example, player.rate = 5.0) , the property observer report the rate correctly.

Manual method If you option-click the forward fast-forward control, it increments by 0.1 from 1.0 to 2.0x (1.1, 1.2, 1.3, etc.) and the play rate changes accordingly (property observer reports these values) If you command-click the fast-forward control the play rate changes to 2, 5, 10, 30 and 60x. (Property observer reports 0.0)

How do you determine what the player rate is, after command-clicking the fast-forward control?

The other think is that if I programmatically or manually change the player rate in the range up to 1.9x, the audio continues to play. If I programmatically change the player rate from 2.0x+, the audio continues to play If I manually change the rate (command-click the player fast-forward control) the audio does not continue

Is there something that needs to be done to keep the audio when manually adjusting the playback rate for 2.0+

![]("https://developer.apple.com/forums/content/attachment/e915f567-b721-4430-9c61-2789a9058002" "title=PlayerControl.png;width=627;height=183")

    var playRateSync: Double = 1.0 {
        didSet{
            // move in specific increment value
            let increment     = 0.1
            let oldValue      = playRateSync
            let playRateSync  = increment * round(oldValue / increment)
            let playRateStr   = String(format: "%.2f", playRateSync)
            playbackLabel.stringValue   = "Playback Rate: \(playRateStr)"
            playbackSlider.doubleValue  = playRateSync
            playbackStepper.doubleValue = playRateSync
        }
    }


    func setPlayRateObserver(player: AVPlayer)
    {
        player.addObserver(self, forKeyPath: "rate", options: [.new, .old, .initial], context: nil)
    }

    override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {
        print("keyPath: \(keyPath), object: \(object), change: \(change)")
        if object as AnyObject? === playerView.player {
            if keyPath == "rate" {
                print("The real rate: \(Double(playerView.player!.rate))")
                if let player = playerView.player
                {
                    if player.rate > 0 {
                        playRateSync = Double(player.rate)
                        print("Rate changed.  New Rate: \(player.rate)")
                    }
                }
            }
        }
    }

Accepted Reply

Hello MisterE,

Question #1 How do you determine what the player rate is, after command-clicking the fast-forward control?

There is currently no way to detect the scanning rate after a user as selected fast forward/rewind. If you file a feedback request we will consider modifying this behavior.

Question #2 Is there something that needs to be done to keep the audio when manually adjusting the playback rate for 2.0+

AVKit intentionally disables audio past 2.0x playback to achieve a scanning effect. There is currently no way to enable audio past 2.0x with AVKit.

See our comments in AVPlayer.timeControlStatus and AVPlayer.rate are wrong during fast forward or backward for more details.

Replies

oddly, I cant edit the post to address the formatting (missing newlines) and the image didnt show up but here is the image to clarify what I mean regarding the fast-forward control.

Option-click here will increment the value by 0.1 from 1.0 to 2.0 (e.g. 1.1, 1.2, 1.3x). Command-click here will rotate between 2x,5x, 10x, 30x and 60x.

The property observer reports back 0.0 once you command-click.

I was still seeking a resolution, alternative method or property to observe for identifying a fast-forward behavior.

https://developer.apple.com/forums/thread/663489

AVPlayer.timeControlStatus and AVPlayer.rate are wrong during fast forward or backward

I found above post, which describes the same behavior. When the fast-forward is engaged, the "rate" reported is zero, although it is clearly not paused but moving at a fast rate. Unfortunately, I have not identified a solution.

Hello MisterE,

Question #1 How do you determine what the player rate is, after command-clicking the fast-forward control?

There is currently no way to detect the scanning rate after a user as selected fast forward/rewind. If you file a feedback request we will consider modifying this behavior.

Question #2 Is there something that needs to be done to keep the audio when manually adjusting the playback rate for 2.0+

AVKit intentionally disables audio past 2.0x playback to achieve a scanning effect. There is currently no way to enable audio past 2.0x with AVKit.

See our comments in AVPlayer.timeControlStatus and AVPlayer.rate are wrong during fast forward or backward for more details.