我正在尝试使用 AVMutableAudioMixInputParameters 的 setVolumeRampFromStartVolume 方法将 AVPlayer 的音量淡化为 0。这是我的代码:
-(void)fadeOutVolume
{
// AVPlayerObject is a property which points to an AVPlayer
AVPlayerItem *myAVPlayerItem = AVPlayerObject.currentItem;
AVAsset *myAVAsset = myAVPlayerItem.asset;
NSArray *audioTracks = [myAVAsset tracksWithMediaType:AVMediaTypeAudio];
NSMutableArray *allAudioParams = [NSMutableArray array];
for (AVAssetTrack *track in audioTracks) {
AVMutableAudioMixInputParameters *audioInputParams = [AVMutableAudioMixInputParameters audioMixInputParametersWithTrack:track];
[audioInputParams setVolumeRampFromStartVolume:1.0 toEndVolume:0 timeRange:CMTimeRangeMake(CMTimeMake(0, 1), CMTimeMake(5, 1))];
[allAudioParams addObject:audioInputParams];
}
AVMutableAudioMix *audioMix = [AVMutableAudioMix audioMix];
[audioMix setInputParameters:allAudioParams];
}
谁能看到这段代码有什么问题?它不会正确淡出音量。