本文介绍了为什么我的AVPlayer音量淡出?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想我AVPlayer的音量淡入0使用AVMutableAudioMixInputParameters的setVolumeRampFromStartVolume方法。这里是我的code:
I'm trying to fade my AVPlayer's volume to 0 using AVMutableAudioMixInputParameters's setVolumeRampFromStartVolume method. Here is my code:
-(void)fadeOutVolume
{
// AVPlayerObject is a property which points to an AVPlayer
AVPlayerItem *myAVPlayerItem = AVPlayerObject.currentItem;
AVAsset *myAVAsset = myAVPlayerItem.asset;
NSArray *audioTracks = [myAVAsset tracksWithMediaType:AVMediaTypeAudio];
NSMutableArray *allAudioParams = [NSMutableArray array];
for (AVAssetTrack *track in audioTracks) {
AVMutableAudioMixInputParameters *audioInputParams = [AVMutableAudioMixInputParameters audioMixInputParametersWithTrack:track];
[audioInputParams setVolumeRampFromStartVolume:1.0 toEndVolume:0 timeRange:CMTimeRangeMake(CMTimeMake(0, 1), CMTimeMake(5, 1))];
[allAudioParams addObject:audioInputParams];
}
AVMutableAudioMix *audioMix = [AVMutableAudioMix audioMix];
[audioMix setInputParameters:allAudioParams];
}
任何人都可以看看有什么不对的code?这是不正确淡出音量。
Can anyone see what's wrong with this code? It's doesn't fade out the volume correctly.
推荐答案
我缺少这个键行:
[myAVPlayerItem setAudioMix:audioMix];
这是一个相对容易解决,我很失望,平时超快速,细心的计算器社会没有发现这个问题。
This was a relatively easy fix and I'm disappointed the usually super-quick and observant StackOverflow community didn't spot the problem.
这篇关于为什么我的AVPlayer音量淡出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!