Im playing a video in AVPlayer, and now I need to mute the audio alone while playing it. Please suggest how to do in objective C.
Thanks, Suresh
Via the Scene Screen Swipe right or left to find the video clip you would like to change the audio options for. 3. Tap on the 3 dots below the video clip and tap on “Mute” or “Unmute” in the dropdown menu.
Mute a portion of the video or the entire videoSelect the clip you want to mute and click on the sound icon to mute it. To mute the entire video, just select the video and click on the sound icon, and you're done!
Since iOS7 you can set the AVPlayer isMuted
property to true
.
In Objective C the property is called muted
.
Reference: https://developer.apple.com/documentation/avfoundation/avplayer/1387544-ismuted
This should see you through...
AVURLAsset *asset = [[avPlayer currentItem] asset]; NSArray *audioTracks = [asset tracksWithMediaType:AVMediaTypeAudio]; // Mute all the audio tracks NSMutableArray *allAudioParams = [NSMutableArray array]; for (AVAssetTrack *track in audioTracks) { AVMutableAudioMixInputParameters *audioInputParams = [AVMutableAudioMixInputParameters audioMixInputParameters]; [audioInputParams setVolume:0.0 atTime:kCMTimeZero]; [audioInputParams setTrackID:[track trackID]]; [allAudioParams addObject:audioInputParams]; } AVMutableAudioMix *audioZeroMix = [AVMutableAudioMix audioMix]; [audioZeroMix setInputParameters:allAudioParams]; [[avPlayer currentItem] setAudioMix:audioZeroMix];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With