AVPlayer rate property does not work?

不羁的心 提交于 2019-11-27 19:52:16

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.

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;

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;
        }
    }
}

I agree with @otto, hi answer solved my problem.

/*
AVAudioProcessingSettings.h


@abstract       Values for time pitch algorithm

@constant      AVAudioTimePitchAlgorithmLowQualityZeroLatency
            Low quality, very inexpensive. Suitable for brief fast-forward/rewind effects, low quality voice.
            Rate snapped to {0.5, 0.666667, 0.8, 1.0, 1.25, 1.5, 2.0}.

@constant      AVAudioTimePitchAlgorithmTimeDomain
            Modest quality, less expensive. Suitable for voice.
            Variable rate from 1/32 to 32.

@constant      AVAudioTimePitchAlgorithmSpectral
            Highest quality, most computationally expensive. Suitable for music.
            Variable rate from 1/32 to 32.

@constant      AVAudioTimePitchAlgorithmVarispeed
            High quality, no pitch correction. Pitch varies with rate.
            Variable rate from 1/32 to 32.
*/

AVF_EXPORT NSString *const AVAudioTimePitchAlgorithmLowQualityZeroLatency NS_AVAILABLE_IOS(7_0);
AVF_EXPORT NSString *const AVAudioTimePitchAlgorithmTimeDomain NS_AVAILABLE(10_9, 7_0);
AVF_EXPORT NSString *const AVAudioTimePitchAlgorithmSpectral NS_AVAILABLE(10_9, 7_0);
AVF_EXPORT NSString *const AVAudioTimePitchAlgorithmVarispeed NS_AVAILABLE(10_9, 7_0);

No it's working fine for me ( xcode 4.2) on ipad 2 ios 5. I used the AVPlayerDemo from the dev resources and modify the rate property with a slider and it's very smooth, definitly no jumps. tho the behavior below 0.2 is odd. maybe the rate is not linear near the extrem values, but definitly smooth. from 0.2 all the way up to 2. I am using videos I captured with the device, that could make a difference.

Bye,

Jean

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!