Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to mute video played in AVPlayer?

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

like image 267
Suresh Avatar asked May 25 '11 07:05

Suresh


People also ask

How do I mute sound in between videos?

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.

How do I mute part of a video online?

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!


2 Answers

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

like image 184
bcattle Avatar answered Sep 30 '22 10:09

bcattle


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]; 
like image 34
friedFingers Avatar answered Sep 30 '22 11:09

friedFingers