Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to avoid affect of Mute Control of the device on AVPlayer

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?

like image 883
spd Avatar asked Oct 10 '11 04:10

spd


2 Answers

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];
like image 55
spd Avatar answered Oct 10 '22 20:10

spd


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)
}
like image 43
petrosmm Avatar answered Oct 10 '22 19:10

petrosmm