gpt4 book ai didi

ios - 单个 AVPlayerItem 中的两个声音淡入淡出

转载 作者:可可西里 更新时间:2023-11-01 05:41:27 24 4
gpt4 key购买 nike

感谢stackoverflow user我能够淡入或淡出一个 AVPlayerTrack。但我找不到在一条轨道上同时执行这两项操作的方法。

这是我正在尝试使用的:

-(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];

}

如果我评论 [allAudioParams addObject:audioInputParams]; 或另一行,这会起作用。但是我不能同时拥有两个输入参数。

最佳答案

我发现了问题。我不需要两个 audioInputParams。事实上,它们似乎以某种方式覆盖了。

如果我删除新的 audioInputParam 并执行两个设置的斜坡,则一切正常。其实这有点误导。 SetRamp 似乎将被覆盖,而“addObject”是覆盖的对象。我在 for 部分得到了这段代码:

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];

感谢@Mundi 试图帮助我。

关于ios - 单个 AVPlayerItem 中的两个声音淡入淡出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17922261/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com