mirror of https://github.com/encounter/SDL.git
Added a hint SDL_HINT_AUDIO_CATEGORY to control the audio category,
determining whether the phone mute switch affects the audio
This commit is contained in:
parent
46ec130528
commit
c08a7a74a5
|
@ -57,6 +57,8 @@ Windows:
|
||||||
Linux:
|
Linux:
|
||||||
* Added an experimental KMS/DRM video driver for embedded development
|
* Added an experimental KMS/DRM video driver for embedded development
|
||||||
|
|
||||||
|
iOS:
|
||||||
|
* Added a hint SDL_HINT_AUDIO_CATEGORY to control the audio category, determining whether the phone mute switch affects the audio
|
||||||
|
|
||||||
---------------------------------------------------------------------------
|
---------------------------------------------------------------------------
|
||||||
2.0.5:
|
2.0.5:
|
||||||
|
|
|
@ -854,6 +854,19 @@ extern "C" {
|
||||||
*/
|
*/
|
||||||
#define SDL_HINT_AUDIO_RESAMPLING_MODE "SDL_AUDIO_RESAMPLING_MODE"
|
#define SDL_HINT_AUDIO_RESAMPLING_MODE "SDL_AUDIO_RESAMPLING_MODE"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief A variable controlling the audio category on iOS and Mac OS X
|
||||||
|
*
|
||||||
|
* This variable can be set to the following values:
|
||||||
|
*
|
||||||
|
* "ambient" - Use the AVAudioSessionCategoryAmbient audio category, will be muted by the phone mute switch (default)
|
||||||
|
* "playback" - Use the AVAudioSessionCategoryPlayback category
|
||||||
|
*
|
||||||
|
* For more information, see Apple's documentation:
|
||||||
|
* https://developer.apple.com/library/content/documentation/Audio/Conceptual/AudioSessionProgrammingGuide/AudioSessionCategoriesandModes/AudioSessionCategoriesandModes.html
|
||||||
|
*/
|
||||||
|
#define SDL_HINT_AUDIO_CATEGORY "SDL_AUDIO_CATEGORY"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief An enumeration of hint priorities
|
* \brief An enumeration of hint priorities
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -25,6 +25,7 @@
|
||||||
/* !!! FIXME: clean out some of the macro salsa in here. */
|
/* !!! FIXME: clean out some of the macro salsa in here. */
|
||||||
|
|
||||||
#include "SDL_audio.h"
|
#include "SDL_audio.h"
|
||||||
|
#include "SDL_hints.h"
|
||||||
#include "../SDL_audio_c.h"
|
#include "../SDL_audio_c.h"
|
||||||
#include "../SDL_sysaudio.h"
|
#include "../SDL_sysaudio.h"
|
||||||
#include "SDL_coreaudio.h"
|
#include "SDL_coreaudio.h"
|
||||||
|
@ -325,7 +326,8 @@ static BOOL update_audio_session(_THIS, SDL_bool open)
|
||||||
@autoreleasepool {
|
@autoreleasepool {
|
||||||
AVAudioSession *session = [AVAudioSession sharedInstance];
|
AVAudioSession *session = [AVAudioSession sharedInstance];
|
||||||
NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
|
NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
|
||||||
NSString *category;
|
/* Set category to ambient by default so that other music continues playing. */
|
||||||
|
NSString *category = AVAudioSessionCategoryAmbient;
|
||||||
NSError *err = nil;
|
NSError *err = nil;
|
||||||
|
|
||||||
if (open_playback_devices && open_capture_devices) {
|
if (open_playback_devices && open_capture_devices) {
|
||||||
|
@ -333,10 +335,17 @@ static BOOL update_audio_session(_THIS, SDL_bool open)
|
||||||
} else if (open_capture_devices) {
|
} else if (open_capture_devices) {
|
||||||
category = AVAudioSessionCategoryRecord;
|
category = AVAudioSessionCategoryRecord;
|
||||||
} else {
|
} else {
|
||||||
/* Set category to ambient so that other music continues playing.
|
const char *hint = SDL_GetHint(SDL_HINT_AUDIO_CATEGORY);
|
||||||
You can change this at runtime in your own code if you need different
|
if (hint) {
|
||||||
behavior. If this is common, we can add an SDL hint for this. */
|
if (SDL_strcasecmp(hint, "AVAudioSessionCategoryAmbient") == 0) {
|
||||||
category = AVAudioSessionCategoryAmbient;
|
category = AVAudioSessionCategoryAmbient;
|
||||||
|
} else if (SDL_strcasecmp(hint, "AVAudioSessionCategorySoloAmbient") == 0) {
|
||||||
|
category = AVAudioSessionCategorySoloAmbient;
|
||||||
|
} else if (SDL_strcasecmp(hint, "AVAudioSessionCategoryPlayback") == 0 ||
|
||||||
|
SDL_strcasecmp(hint, "playback") == 0) {
|
||||||
|
category = AVAudioSessionCategoryPlayback;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (![session setCategory:category error:&err]) {
|
if (![session setCategory:category error:&err]) {
|
||||||
|
|
Loading…
Reference in New Issue