4

In my iPhone application I want to mute & unmute MPMoviePlayerController. I have searched a lot but I am unable to succeed. Is it possible to mute audio in MPMoviePlayer controller? Please help me out. Thanks in advance.

Jyotsna Kadam
  • 213
  • 5
  • 12

2 Answers2

2
[[MPMusicPlayerController applicationMusicPlayer] setVolume:0];

This Line will mute the sound(hopefully)..:)

rptwsthi
  • 10,094
  • 10
  • 68
  • 109
  • I have tried by using this API but it wont work because it is for MPMusicPlayercontroller & I want to mute MPMoviePlayerController. – Jyotsna Kadam May 24 '11 at 09:43
  • WELL, MPMusicPlayercontroller, MPMoviePlayerController are diffrent? or it just a mistake (of spelling or something). – rptwsthi May 24 '11 at 09:52
  • +1 for correct answer - @Jyotsna: you just create an instance of the `MPMusicPlayerController` addionally to your `MPMoviePlayerController` and adjust the volume. That `MPMusicPlayerController` instance is almost inactive apart from being used for adjusting the volume. – Till May 24 '11 at 09:56
  • @rptwsthi: MPMoviePlayerController do not support applicationMusicPlayer method. – Jyotsna Kadam May 24 '11 at 09:58
  • @Till: Means it's not possible to mute the audio for MPMoviePlayerController? – Jyotsna Kadam May 24 '11 at 10:00
  • 1
    setVolume is deprecated in iOS7++. It has also the disadvantage that a "sound turned off" icon is shown for a second. The answer in says that it is not possible to turn off the sound of a MPMoviePlayerController. – Reinhard Männer Jul 05 '14 at 06:36
  • should be -1 on votes. This is not a correct answer. – LightningStryk Jun 18 '15 at 21:45
2

Use this to mute.

NSError *error;
if ( ![[AVAudioSession sharedInstance] setActive:NO error:&error] ) {
    NSLog(@"Error encountered: %@", [error localizedDescription]);
}

You will have to include the AVFoundation framework.

Deepak Danduprolu
  • 44,595
  • 12
  • 101
  • 105
  • Hi deepak thanks for your instant reply but it also not worked for me, I am checking it on simulator. – Jyotsna Kadam May 24 '11 at 09:57
  • 2
    +1 for correct answer - this works just like the solution supplied by rptwsthi. You might need to adjust the player settings on the usage of the audio session to get this to work properly: `useApplicationAudioSession` – Till May 24 '11 at 10:06
  • @Till: I also tried to create by using instance still not working. – Jyotsna Kadam May 24 '11 at 10:15
  • Thanks!!! I will also check this on iPad or on iPhone. May be I am working on simulator because of that it's not reflecting any changes. – Jyotsna Kadam May 24 '11 at 11:13