AVPlayer Volume Control

后端 未结 5 771
醉梦人生
醉梦人生 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:42

    I used below code to mute AVPlayer.

     float volSet = 0 ;
     AVAsset *avAsset = [[avPlayer currentItem] asset] ;
    NSArray *audioTracks = [avAsset tracksWithMediaType:AVMediaTypeAudio] ;
    
     NSMutableArray *allAudioParams = [NSMutableArray array] ;
    for(AVAssetTrack *track in audioTracks){
     AVMutableAudioMixInputParameters *audioInputParams = [AVMutableAudioMixInputParameters audioMixInputParameters] ;
    [audioInputParams setVolume:volSet atTime:kCMTimeZero] ;
     [audioInputParams setTrackID:[track trackID]] ;
     [allAudioParams addObject:audioInputParams];
    }
     AVMutableAudioMix *audioVolMix = [AVMutableAudioMix audioMix] ;
    [audioVolMix setInputParameters:allAudioParams];
     [[avPlayer currentItem] setAudioMix:audioVolMix];
    

提交回复
热议问题