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?
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;
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.
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;
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With