AVMutableAudioMix 简单问题

发布于 2024-11-14 23:33:26 字数 120 浏览 2 评论 0 原文

只是想了解,我到底可以用这个 AVMutableAudioMix 类做什么,一旦我将 PlayerItems(资产)插入到 AudioMix 中,我可以一次播放它们还是使用 AVPlayer 同时播放其中一些并更改参数动态地?

just want to understand , what exactly I can do with this AVMutableAudioMix class, once I will insert PlayerItems (Assets) in to the AudioMix, can I play them one at the time or some of them at the same time with AVPlayer and change the parameters dynamically?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

他是夢罘是命 2024-11-21 23:33:26

我认为您可能错误地想象了它。 AVMutableAudioMix 实例实际上是一个 属性。首先使用 tracksWithMediaType: 并创建一个 AVMutableAudioMixInputParameters 实例使用 audioMixInputParametersWithTrack:。在该输入参数实例上设置任何音频属性(例如 setVolume:atTime)。

然后,您需要将输入参数添加到 AVMutableAudioMix 实例上。然后您需要将其添加到播放器项目中。我知道这听起来令人困惑,但这正是 AVFoundation 处理几乎所有事物的方式。术语到处都是,但几乎所有东西都有层次结构。

所以一般的层次结构是这样的:player->playerItem->audioMix->inputParameters。将音量从 5 秒标记降低到 7 秒标记的代码应如下所示:

AVAssetTrack *audioTrack = [[self.player.currentItem.asset tracksWithMediaType:AVMediaTypeAudio] objectAtIndex:0];
AVMutableAudioMixInputParameters *params = [AVMutableAudioMixInputParameters audioMixInputParametersWithTrack:audioTrack];
[params setVolumeRampFromStartVolume:1.0 toEndVolume:0.5 timeRange:CMTimeRangeMake(CMTimeMake(5,1), CMTimeMake(2,1))];

AVMutableAudioMix *audioMix = [AVMutableAudioMix audioMix];
audioMix.inputParameters = [NSArray arrayWithObject:params];

self.player.currentItem.audioMix = audioMix;

至于动态执行此操作,您可以,但只能使用本地文件(而不是从互联网流式传输)。我可能会尝试将此audioMix保留为ivar,并在每次您想要发生某些事情时尝试重置参数。如果这不起作用,您可能必须每次都创建一个 AVMutableAudioMix 实例,不确定。

另请参阅这篇文章

I think you might be visualizing it incorrectly. An AVMutableAudioMix instance is actually a property on the AVPlayerItem class. First grab the track of the asset using tracksWithMediaType: and create an AVMutableAudioMixInputParameters instance using audioMixInputParametersWithTrack:. Set any audio properties on that inputparameters instance, (for instance setVolume:atTime).

Then you need to add the input parameters onto an AVMutableAudioMix instance. Then you need to add this to an player item. I know this sounds confusing, but this is exactly how AVFoundation works with just about everything. There's terms flying around all over the place, but pretty much everything has a hierarchy.

So the general hierarchy is this: player->playerItem->audioMix->inputParameters. The code to ramp down the volume from the 5 to 7 second mark should look something like this:

AVAssetTrack *audioTrack = [[self.player.currentItem.asset tracksWithMediaType:AVMediaTypeAudio] objectAtIndex:0];
AVMutableAudioMixInputParameters *params = [AVMutableAudioMixInputParameters audioMixInputParametersWithTrack:audioTrack];
[params setVolumeRampFromStartVolume:1.0 toEndVolume:0.5 timeRange:CMTimeRangeMake(CMTimeMake(5,1), CMTimeMake(2,1))];

AVMutableAudioMix *audioMix = [AVMutableAudioMix audioMix];
audioMix.inputParameters = [NSArray arrayWithObject:params];

self.player.currentItem.audioMix = audioMix;

As far as doing this dynamically, you can, but only with local files (as opposed to streaming from the internet). I would probably try to keep this audioMix as an ivar and try resetting the params every time you want something to happen. If that doesn't work, you may have to create an instance of AVMutableAudioMix every time, not sure.

Also see this post and this.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文