AVMutableAudioMix 简单问题
只是想了解,我到底可以用这个 AVMutableAudioMix 类做什么,一旦我将 PlayerItems(资产)插入到 AudioMix 中,我可以一次播放它们还是使用 AVPlayer 同时播放其中一些并更改参数动态地?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为您可能错误地想象了它。 AVMutableAudioMix 实例实际上是一个 属性。首先使用 tracksWithMediaType: 并创建一个 AVMutableAudioMixInputParameters 实例使用 audioMixInputParametersWithTrack:。在该输入参数实例上设置任何音频属性(例如 setVolume:atTime)。
然后,您需要将输入参数添加到 AVMutableAudioMix 实例上。然后您需要将其添加到播放器项目中。我知道这听起来令人困惑,但这正是 AVFoundation 处理几乎所有事物的方式。术语到处都是,但几乎所有东西都有层次结构。
所以一般的层次结构是这样的:player->playerItem->audioMix->inputParameters。将音量从 5 秒标记降低到 7 秒标记的代码应如下所示:
至于动态执行此操作,您可以,但只能使用本地文件(而不是从互联网流式传输)。我可能会尝试将此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:
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.