How to avoid affect of Mute Control of the device on AVPlayer
Asked Answered
V

2

6

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?

Volnay answered 10/10, 2011 at 4:14 Comment(0)
V
12

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];
Volnay answered 10/10, 2011 at 10:45 Comment(0)
H
1

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)
}
Herniorrhaphy answered 15/8, 2017 at 23:20 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.