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?
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];
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)
}
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