Skip to content

Commit 921e4d3

Browse files
committed
options.audio.allowMobileWebAudio
1 parent 067b4e3 commit 921e4d3

File tree

2 files changed

+23
-15
lines changed

2 files changed

+23
-15
lines changed

Backends/HTML5/kha/SystemImpl.hx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ class SystemImpl {
460460
}
461461
// canvas.getContext("2d").scale(transform, transform);
462462

463-
if (!mobile && kha.audio2.Audio._init()) {
463+
if ((!mobile || options.audio.allowMobileWebAudio) && kha.audio2.Audio._init()) {
464464
SystemImpl._hasWebAudio = true;
465465
kha.audio2.Audio1._init();
466466
}

Sources/kha/System.hx

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,35 @@ package kha;
22

33
import kha.WindowOptions;
44

5+
@:structInit
6+
private class AudioOptions {
7+
/** Allow `audio2.Audio` api initialization on mobile browsers (only for HTML5 target) **/
8+
public var allowMobileWebAudio = false;
9+
}
10+
511
@:structInit
612
class SystemOptions {
7-
@:optional public var title: String = "Kha";
8-
@:optional public var width: Int = -1;
9-
@:optional public var height: Int = -1;
10-
@:optional public var window: WindowOptions = null;
11-
@:optional public var framebuffer: FramebufferOptions = null;
13+
public var title: String = "Kha";
14+
public var width: Int = -1;
15+
public var height: Int = -1;
16+
public var window: WindowOptions = null;
17+
public var framebuffer: FramebufferOptions = null;
18+
public var audio: AudioOptions = null;
1219

1320
/**
14-
* Used to provide parameters for System.start
21+
* Used to provide parameters for `System.start`
1522
* @param title The application title is the default window title (unless the window parameter provides a title of its own)
1623
* and is used for various other purposes - for example for save data locations
17-
* @param width Just a shortcut which overwrites window.width if set
18-
* @param height Just a shortcut which overwrites window.height if set
24+
* @param width Just a shortcut which overwrites `window.width` if set
25+
* @param height Just a shortcut which overwrites `window.height` if set
1926
* @param window Optionally provide window options
2027
* @param framebuffer Optionally provide framebuffer options
28+
* @param audio Optionally provide audio options
2129
*/
22-
public function new(title: String = "Kha", ?width: Int = -1, ?height: Int = -1, window: WindowOptions = null, framebuffer: FramebufferOptions = null) {
30+
public function new(title: String = "Kha", ?width: Int = -1, ?height: Int = -1, ?window: WindowOptions, ?framebuffer: FramebufferOptions,
31+
?audio: AudioOptions) {
2332
this.title = title;
24-
this.window = window == null ? {} : window;
33+
this.window = window ?? {};
2534

2635
if (width > 0) {
2736
this.window.width = width;
@@ -39,11 +48,10 @@ class SystemOptions {
3948
this.height = this.window.height;
4049
}
4150

42-
if (this.window.title == null) {
43-
this.window.title = title;
44-
}
51+
this.window.title ??= title;
4552

46-
this.framebuffer = framebuffer == null ? {} : framebuffer;
53+
this.framebuffer = framebuffer ?? {};
54+
this.audio = audio ?? {};
4755
}
4856
}
4957

0 commit comments

Comments
 (0)