AVPlayer Volume Control

后端 未结 5 923
醉梦人生
醉梦人生 2021-01-18 03:57

I want to create a button that mutes the audio from an AVPlayer.

Why can´t I use .volume with AVPlayer, only with AVAudioPlayer? Is there another way to change the v

5条回答
  •  感动是毒
    2021-01-18 04:43

    best way is as following

      AVAssetTrack* assetTrackAudio = [arrayTracks objectAtIndex:0];
    
        AVMutableAudioMixInputParameters* audioInputParams = [AVMutableAudioMixInputParameters audioMixInputParameters];
        [audioInputParams setVolume:currentVolume atTime:playerCursorStartPosition];
        [audioInputParams setTrackID:[assetTrackAudio trackID]];
    
        NSArray* audioParams = [NSArray arrayWithObject:audioInputParams];
        AVMutableAudioMix* audioMix = [AVMutableAudioMix audioMix];
        [audioMix setInputParameters:audioParams];
    
        AVPlayerItem* item = [player currentItem];
        [item setAudioMix:audioMix];
    

提交回复
热议问题