我正在尝试使用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];
}
谁能看到这段代码有什么问题吗?无法正确淡出音量。
最佳答案
我错过了这条关键线:
[myAVPlayerItem setAudioMix:audioMix];
这是一个相对容易的修复程序,我对通常 super 快速且细心的StackOverflow社区没有发现问题感到失望。