Two sounds fade in one AVPlayerItem

Thanks to https://stackoverflow.com/a/166778/2/2/2/2/2/2/2/2/2/2/2/3/2/2/2/2/3/2/2/2/2/3/2/2/2/2/3/2/3/16/16/16/12/25/12/16/16/16/16/16/16/12/16/translation.html Thanks to https://stackoverflow.com/a/168778/how-to-free-file-from-a-file-in-java/167238## But I can’t find a way to do this on one track.

This is what I am trying to use:

-(void)fadeOutVolume { AVPlayerItem *myAVPlayerItem = self.songPlayer.currentItem; AVAsset *myAVAsset = myAVPlayerItem.asset; NSArray *audioTracks = [myAVAsset tracksWithMediaType:AVMediaTypeAudio]; NSMutableArray *allAudioParams = [NSMutableArray array]; for (AVAssetTrack *track in audioTracks) { AVMutableAudioMixInputParameters *audioInputParams = [AVMutableAudioMixInputParameters audioMixInputParametersWithTrack:track]; CMTime fadeDuration = CMTimeMakeWithSeconds(5, 600); CMTime fadeOutStartTime = CMTimeMakeWithSeconds(CMTimeGetSeconds(myAVPlayerItem.duration)-5, 600); CMTime fadeInStartTime = CMTimeMakeWithSeconds(0, 600); [audioInputParams setVolumeRampFromStartVolume:1.0 toEndVolume:0 timeRange:CMTimeRangeMake(fadeOutStartTime, fadeDuration)]; AVMutableAudioMixInputParameters *audioInputParams2 = [AVMutableAudioMixInputParameters audioMixInputParametersWithTrack:track]; [audioInputParams2 setVolumeRampFromStartVolume:0.0 toEndVolume:1.0 timeRange:CMTimeRangeMake(fadeInStartTime, fadeDuration)]; [allAudioParams addObject:audioInputParams]; [allAudioParams addObject:audioInputParams2]; } AVMutableAudioMix *audioMix = [AVMutableAudioMix audioMix]; [audioMix setInputParameters:allAudioParams]; [myAVPlayerItem setAudioMix:audioMix]; } 

This works if I comment [allAudioParams addObject:audioInputParams]; or another line. But I can not have two input parameters at the same time.

+4
source share
2 answers

I found a problem. I do not need two audio interfaces. In fact, it seems that they are somehow redefined.

If I remove the new audioInputParam and make two ramp sets, everything works fine. This is actually a curious miss. SetRamp seems to be overridden, and "addObject" is the one that overrides. I ended up with this code for the part:

 AVMutableAudioMixInputParameters *audioInputParams = [AVMutableAudioMixInputParameters audioMixInputParametersWithTrack:track]; CMTime fadeDuration = CMTimeMakeWithSeconds(5, 600); CMTime fadeOutStartTime = CMTimeMakeWithSeconds(CMTimeGetSeconds(myAVPlayerItem.duration)-5, 600); CMTime fadeInStartTime = CMTimeMakeWithSeconds(0, 600); [audioInputParams setVolumeRampFromStartVolume:1.0 toEndVolume:0 timeRange:CMTimeRangeMake(fadeOutStartTime, fadeDuration)]; [audioInputParams setVolumeRampFromStartVolume:0.0 toEndVolume:1.0 timeRange:CMTimeRangeMake(fadeInStartTime, fadeDuration)]; [allAudioParams addObject:audioInputParams]; 

Thanks @Mundi for trying to help me.

+3
source

You can set only a one-time run level. This seems to be logical, right?

If you want to change the volume again later, use

 setVolume:atTime: 

This method adds a volume ramp starting over time. This volume setting remains valid until the end of the track, unless you set a different volume level to start later.

EDIT:

Perhaps this answer is not entirely correct. There is nothing in the documents that would indicate this limitation.

But I noticed that you fadeOutStratTime over the tracks and set fadeOutStratTime based on myAVPlayerItem - maybe there is a logical error leading to an error.

+1
source

Source: https://habr.com/ru/post/1494042/


All Articles