Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AVPlayer rate property does not work?

Tags:

avplayer

so it would appear that the only values that actually work are 0.0, 0.5, 1.0, and 2.0...

i tried setting it to 0.25 since I want it to play at 1/4th of the natural speed, but it played it at 1/2 of the natural speed instead. can anyone confirm this?

like image 644
bogardon Avatar asked Jul 08 '11 20:07

bogardon


3 Answers

The play rate restriction appears to be due to pitch correction, which is now configurable in iOS 7 or later.

// This prevents the play rate from going below 1/2.
playerItem.audioTimePitchAlgorithm = AVAudioTimePitchAlgorithmLowQualityZeroLatency;

That seems to be the default setting:

Low quality and very low computationally intensive pitch algorithm. Suitable for brief fast-forward and rewind effects as well as low quality voice. The rate is snapped to {0.5, 0.666667, 0.8, 1.0, 1.25, 1.5, 2.0}.

The other three algorithm settings let you vary the play rate down to 1/32. For example, AVAudioTimePitchAlgorithmVarispeed turns off pitch correction.

// Enable play rates down to 1/32.
playerItem.audioTimePitchAlgorithm = AVAudioTimePitchAlgorithmVarispeed;
like image 80
otto Avatar answered Oct 07 '22 10:10

otto


Confirmed. I actually had a ticket with Apple DTS open for this issue and a bug filed. The only supported values are 0.50, 0.67, 0.80, 1.0, 1.25, 1.50, and 2.0. All other settings are rounded to nearest value.

like image 29
Jeff Avatar answered Oct 07 '22 09:10

Jeff


I found that smaller values are indeed supported, but all tracks in the AVPlayerItem have to support the speed. However, Apple does not provide a property on individual tracks that would indicate what rates are supported, there is only the property canPlaySlowForward on AVPlayerItem.

What i found is, that AVPlayerItems with an audio track cannot play at rates slower than 0.5. However, if there is only a video track, the rate can have an arbitrary small value like 0.01. I will try to write a category that checks on-the-fly which values are supported and disable unsupported tracks if needed.

br denis

UPDATE

I wrote a function which you can call whenever you want to set the rate for video below 0.5. It enables/disables all audio tracks.

- (void)enableAudioTracks:(BOOL)enable inPlayerItem:(AVPlayerItem*)playerItem
{
    for (AVPlayerItemTrack *track in playerItem.tracks)
    {
        if ([track.assetTrack.mediaType isEqual:AVMediaTypeAudio])
        {
            track.enabled = enable;
        }
    }
}
like image 35
denrase Avatar answered Oct 07 '22 09:10

denrase