From 2bc7a39a0d01498567aef958908b4bdba4071c8f Mon Sep 17 00:00:00 2001
From: Yoann Lopes <yoann.lopes@digia.com>
Date: Wed, 21 May 2014 13:40:42 +0200
Subject: [PATCH] CoreAudio: make sure audio stops playing when the device is
 muted.

The audio session's category was set to Playback, which implies that
audio is still audible even after setting the device to silent mode or
locking the screen. This shouldn't be the default behavior.
We now set it to Ambient, which preserves mixing with other apps
but makes sure sound is turned off when it should.

Task-number: QTBUG-39036
Change-Id: Ic36668d73f3179dc38b41023e380e15f8c8517e0
Reviewed-by: Christian Stromme <christian.stromme@digia.com>
---
 src/plugins/coreaudio/coreaudiosessionmanager.mm | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/src/plugins/coreaudio/coreaudiosessionmanager.mm b/src/plugins/coreaudio/coreaudiosessionmanager.mm
index 04c8b6ed4..6a8e97f4a 100644
--- a/src/plugins/coreaudio/coreaudiosessionmanager.mm
+++ b/src/plugins/coreaudio/coreaudiosessionmanager.mm
@@ -216,8 +216,9 @@ CoreAudioSessionManager::CoreAudioSessionManager() :
 {
     m_sessionObserver = [[CoreAudioSessionObserver alloc] initWithAudioSessionManager:this];
     setActive(true);
-    //set default category to just Playback and only switch if we need more permissions
-    setCategory(CoreAudioSessionManager::Playback, CoreAudioSessionManager::MixWithOthers);
+    // Set default category to Ambient (implies MixWithOthers). This makes sure audio stops playing
+    // if the screen is locked or if the Silent switch is toggled.
+    setCategory(CoreAudioSessionManager::Ambient, CoreAudioSessionManager::None);
 }
 
 CoreAudioSessionManager::~CoreAudioSessionManager()
-- 
GitLab