Merge pull request #83409 from jfriv/add-audiosession-options
[3.x] Add project settings for AVAudioSessionCategory on iOS
This commit is contained in:
commit
4126326197
3 changed files with 42 additions and 2 deletions
|
@ -1095,6 +1095,10 @@ ProjectSettings::ProjectSettings() {
|
||||||
|
|
||||||
GLOBAL_DEF_RST("audio/general/text_to_speech", false);
|
GLOBAL_DEF_RST("audio/general/text_to_speech", false);
|
||||||
|
|
||||||
|
GLOBAL_DEF("audio/general/ios/session_category", 0);
|
||||||
|
ProjectSettings::get_singleton()->set_custom_property_info("audio/general/ios/session_category", PropertyInfo(Variant::INT, "audio/general/ios/session_category", PROPERTY_HINT_ENUM, "Ambient,Multi Route,Play and Record,Playback,Record,Solo Ambient"));
|
||||||
|
GLOBAL_DEF("audio/general/ios/mix_with_others", false);
|
||||||
|
|
||||||
PoolStringArray extensions = PoolStringArray();
|
PoolStringArray extensions = PoolStringArray();
|
||||||
extensions.push_back("gd");
|
extensions.push_back("gd");
|
||||||
if (Engine::get_singleton()->has_singleton("GodotSharp")) {
|
if (Engine::get_singleton()->has_singleton("GodotSharp")) {
|
||||||
|
|
|
@ -284,6 +284,13 @@
|
||||||
If [code]true[/code], microphone input will be allowed. This requires appropriate permissions to be set when exporting to Android or iOS.
|
If [code]true[/code], microphone input will be allowed. This requires appropriate permissions to be set when exporting to Android or iOS.
|
||||||
[b]Note:[/b] If the operating system blocks access to audio input devices (due to the user's privacy settings), audio capture will only return silence. On Windows 10 and later, make sure that apps are allowed to access the microphone in the OS' privacy settings.
|
[b]Note:[/b] If the operating system blocks access to audio input devices (due to the user's privacy settings), audio capture will only return silence. On Windows 10 and later, make sure that apps are allowed to access the microphone in the OS' privacy settings.
|
||||||
</member>
|
</member>
|
||||||
|
<member name="audio/general/ios/mix_with_others" type="bool" setter="" getter="" default="false">
|
||||||
|
Sets the [url=https://developer.apple.com/documentation/avfaudio/avaudiosession/categoryoptions/1616611-mixwithothers]mixWithOthers[/url] option for the AVAudioSession on iOS. This will override the mix behavior, if the category is set to [code]Play and Record[/code], [code]Playback[/code], or [code]Multi Route[/code].
|
||||||
|
[code]Ambient[/code] always has this set per default.
|
||||||
|
</member>
|
||||||
|
<member name="audio/general/ios/session_category" type="int" setter="" getter="" default="0">
|
||||||
|
Sets the [url=https://developer.apple.com/documentation/avfaudio/avaudiosessioncategory]AVAudioSessionCategory[/url] on iOS. Use the [code]Playback[/code] category to get sound output, even if the phone is in silent mode.
|
||||||
|
</member>
|
||||||
<member name="audio/general/text_to_speech" type="bool" setter="" getter="" default="false">
|
<member name="audio/general/text_to_speech" type="bool" setter="" getter="" default="false">
|
||||||
If [code]true[/code], text-to-speech support is enabled, see [method OS.tts_get_voices] and [method OS.tts_speak].
|
If [code]true[/code], text-to-speech support is enabled, see [method OS.tts_get_voices] and [method OS.tts_speak].
|
||||||
[b]Note:[/b] Enabling TTS can cause addition idle CPU usage and interfere with the sleep mode, so consider disabling it if TTS is not used.
|
[b]Note:[/b] Enabling TTS can cause addition idle CPU usage and interfere with the sleep mode, so consider disabling it if TTS is not used.
|
||||||
|
|
|
@ -49,6 +49,15 @@ extern void iphone_finish();
|
||||||
|
|
||||||
@implementation AppDelegate
|
@implementation AppDelegate
|
||||||
|
|
||||||
|
enum {
|
||||||
|
SESSION_CATEGORY_AMBIENT,
|
||||||
|
SESSION_CATEGORY_MULTI_ROUTE,
|
||||||
|
SESSION_CATEGORY_PLAY_AND_RECORD,
|
||||||
|
SESSION_CATEGORY_PLAYBACK,
|
||||||
|
SESSION_CATEGORY_RECORD,
|
||||||
|
SESSION_CATEGORY_SOLO_AMBIENT,
|
||||||
|
};
|
||||||
|
|
||||||
static ViewController *mainViewController = nil;
|
static ViewController *mainViewController = nil;
|
||||||
|
|
||||||
+ (ViewController *)viewController {
|
+ (ViewController *)viewController {
|
||||||
|
@ -95,8 +104,28 @@ static ViewController *mainViewController = nil;
|
||||||
|
|
||||||
mainViewController = viewController;
|
mainViewController = viewController;
|
||||||
|
|
||||||
// prevent to stop music in another background app
|
int sessionCategorySetting = GLOBAL_GET("audio/general/ios/session_category");
|
||||||
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryAmbient error:nil];
|
|
||||||
|
// Initialize with default Ambient category.
|
||||||
|
AVAudioSessionCategory category = AVAudioSessionCategoryAmbient;
|
||||||
|
|
||||||
|
if (sessionCategorySetting == SESSION_CATEGORY_MULTI_ROUTE) {
|
||||||
|
category = AVAudioSessionCategoryMultiRoute;
|
||||||
|
} else if (sessionCategorySetting == SESSION_CATEGORY_PLAY_AND_RECORD) {
|
||||||
|
category = AVAudioSessionCategoryPlayAndRecord;
|
||||||
|
} else if (sessionCategorySetting == SESSION_CATEGORY_PLAYBACK) {
|
||||||
|
category = AVAudioSessionCategoryPlayback;
|
||||||
|
} else if (sessionCategorySetting == SESSION_CATEGORY_RECORD) {
|
||||||
|
category = AVAudioSessionCategoryRecord;
|
||||||
|
} else if (sessionCategorySetting == SESSION_CATEGORY_SOLO_AMBIENT) {
|
||||||
|
category = AVAudioSessionCategorySoloAmbient;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (GLOBAL_GET("audio/general/ios/mix_with_others")) {
|
||||||
|
[[AVAudioSession sharedInstance] setCategory:category withOptions:AVAudioSessionCategoryOptionMixWithOthers error:nil];
|
||||||
|
} else {
|
||||||
|
[[AVAudioSession sharedInstance] setCategory:category error:nil];
|
||||||
|
}
|
||||||
|
|
||||||
bool keep_screen_on = bool(GLOBAL_DEF("display/window/energy_saving/keep_screen_on", true));
|
bool keep_screen_on = bool(GLOBAL_DEF("display/window/energy_saving/keep_screen_on", true));
|
||||||
OSIPhone::get_singleton()->set_keep_screen_on(keep_screen_on);
|
OSIPhone::get_singleton()->set_keep_screen_on(keep_screen_on);
|
||||||
|
|
Loading…
Reference in a new issue