AVPlayer音量淡入

时间:2017-09-15 07:43:10

标签: ios objective-c avplayer fadein

我需要在开始时进行音量淡入,并使用AVPlayer播放流式广播。我找到了一个例子:

assert(_player.currentItem.tracks.firstObject);
AVMutableAudioMixInputParameters* fadeIn = [AVMutableAudioMixInputParameters audioMixInputParametersWithTrack:_player.currentItem.tracks.firstObject];
[fadeIn setVolume:0 atTime:kCMTimeZero];
[fadeIn setVolume:1 atTime:CMTimeMake(2, 1)];
NSMutableArray* paramsArray = [NSMutableArray new];
[paramsArray addObject:fadeIn];
AVMutableAudioMix* audioMix = [AVMutableAudioMix audioMix];
audioMix.inputParameters = paramsArray;
_player.currentItem.audioMix = audioMix;

但是实时我在第一行崩溃并且IDE警告"不兼容的指针类型发送' AVPlayerItemTrack * _Nullable'参数类型' AVAssetTrack * _Nullable'"在第二行。

我最近与avplayer合作并需要帮助

谢谢。

1 个答案:

答案 0 :(得分:0)

我有解决方法使用MPVolumeView

for (UIView *view in [volumeView subviews]){
        if (![view.class.description isEqualToString:@"MPVolumeSlider"]) {
            continue;
        }

        UISlider *volumeViewSlider = (UISlider *)view;
        // volume from 0 to 1 
        [volumeViewSlider setValue:volume animated:YES];
        [volumeViewSlider sendActionsForControlEvents:UIControlEventTouchUpInside];

        break;
    }

希望有所帮助