开发者

AVPlayer rate property does not work?

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开发者_C百科 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;
        }
    }
}


(Xcode 11.6, iOS 13.6, Swift 5)

It doesn't work with

player.rate = 2.0

It works with

player.playImmediately(atRate: 3.0)


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜