6
votes

I am using AVPlayer for playing videos in my iPhone application. When I mute the device volume using Mute COntrol provided in the device, AVPlayer volume is also mute. As per the documentation this is the right behavior.

But, it does not happen with the default Player of Apple (Playing Music, Playing videos from Photos app). Why is this? How do I achieve this default behavior?

2

2 Answers

11
votes

I called the following set of code in my appDidFinishLaunching:

NSError *sessionError = nil;
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:&sessionError];
[[AVAudioSession sharedInstance] setActive:YES error:&sessionError];
1
votes

For Swift 3 the following will help. In the example below it is run when the view loads:

override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view.

    // avoid affect of Mute Control of the device on AVPlayer
    try? AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayback)
    try? AVAudioSession.sharedInstance().setActive(true)
}