gpt4 book ai didi

avplayer - 调整AVAudioMix音量属性在iOS9中没有效果

转载 作者:行者123 更新时间:2023-12-01 15:42:09 26 4
gpt4 key购买 nike

我有一个应用程序,它通过 AVMutableComposition 将本地文件加载到 avPlayer 中,它可能有多达 6 个音频和视频轨道作为合成的一部分。

我有一个 UISlider,用于调整播放器中每个轨道的音量。

下面是用于更新音量的代码。

- (void)updateVolumeForTake:(Take *)take
{
NSInteger trackID = // method that gets trackID

AVMutableAudioMix *audioMix = self.player.currentItem.audioMix.mutableCopy;
NSMutableArray *inputParameters = audioMix.inputParameters.mutableCopy;

AVMutableAudioMixInputParameters *audioInputParams = [inputParameters filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:kTrackIdPredicate, trackID]].firstObject;

[audioInputParams setVolume:myNewVolumeFloat atTime:myDesiredTime];

audioMix.inputParameters = inputParameters;

AVPlayerItem *playerItem = self.player.currentItem;
playerItem.audioMix = audioMix;
}

此功能目前已在 appStore 中使用,自 iOS6 以来一直有效,并且一直运行没有问题。在运行 iOS9 的设备上,上述内容不再起作用。我查看了发行说明,虽然其中提到了 AVFoundation,但我没有看到任何有关 AVAudioMix 的内容。我用 google 搜索了一下,没有发现其他人遇到此问题。

我还尝试创建一个新项目,只使用 AVPlayer 和 UISlider,我看到了相同的行为。

我的问题如下,有其他人遇到过这个问题吗?有人知道与此相关的已知错误吗?

最佳答案

我找到了解决方案,但不幸的是没有找到确切的原因。

我不能说我完全理解为什么这解决了我的问题,但这里是解决方案,并试图解释为什么它解决了我遇到的问题。

- (void)updateVolumeForTake:(Take *)take
{

AVMutableAudioMix *audioMix = [AVMutableAudioMix audioMix];
NSMutableArray *inputParameters = [self.inputParameters filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:kNotTrackIdPredicate, myTrackID]].mutableCopy;

AVCompositionTrack *track = (AVCompositionTrack *)[self.composition trackWithTrackID:myTrackID];
AVMutableAudioMixInputParameters *audioInputParams = [AVMutableAudioMixInputParameters audioMixInputParametersWithTrack:track];
[audioInputParams setVolume:myDesiredVolume atTime:kCMTimeZero];

[inputParameters addObject:audioInputParams];
audioMix.inputParameters = inputParameters;

AVPlayerItem *playerItem = self.player.currentItem;
playerItem.audioMix = audioMix;

self.inputParameters = inputParameters;
}

正如你在上面看到的,我已经停止使用 AVAudioMix 及其 inputParameters 的可变副本,而是为 inputParameters 创建了一个新的 AVAudioMix 和 NSMutableArray。新的 inputParameters 数组是现有 inputParameters 的副本(从属性“self.inputParameters”引用)减去与我希望更改的轨道匹配的轨道。

其次,我使用我希望编辑音量的轨道创建一个新的 AVMutableAudioMixInputParameters 实例(之前我是通过匹配 trackID 来引用现有参数并修改它们)。我编辑将其添加到我的新数组中,并使其成为 currentItem 的音频混合。

我不能肯定地说为什么这会修复它,但它对我来说确实如此,我想知道当我重新分配playerItem的audioMix时,是否所有可变副本都没有被发现为不同的,这就是为什么我没有听到音量有任何变化。 (尽管这似乎值得怀疑)。

无论如何,我的问题已经解决,我希望这可以帮助任何有类似问题的人。

关于avplayer - 调整AVAudioMix音量属性在iOS9中没有效果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32698152/

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