I am trying to bring my AVPlayer volume to 0 using the AVMutableAudioMixInputParameters setVolumeRampFromStartVolume method. Here is my code:
-(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]; }
Can anyone see what is wrong with this code? It does not equalize the volume correctly.
I missed this key line:
[myAVPlayerItem setAudioMix:audioMix];
This was a relatively simple fix, and I am disappointed that the usually super-fast and observable StackOverflow community did not reveal a problem.
[audioInputParams setVolumeRampFromStartVolume:1.0 toEndVolume:0 timeRange:CMTimeRangeMake(CMTimeMake(0, 1), CMTimeMake(5, 1))];
in this case you set the start to 1.0 and end at 0, so only the sound disappears