diff --git a/Backends/HTML5/kha/SystemImpl.hx b/Backends/HTML5/kha/SystemImpl.hx
index 7feee5120..c7b77e455 100644
--- a/Backends/HTML5/kha/SystemImpl.hx
+++ b/Backends/HTML5/kha/SystemImpl.hx
@@ -460,7 +460,7 @@ class SystemImpl {
}
// canvas.getContext("2d").scale(transform, transform);
- if (!mobile && kha.audio2.Audio._init()) {
+ if ((!mobile || options.audio.allowMobileWebAudio) && kha.audio2.Audio._init()) {
SystemImpl._hasWebAudio = true;
kha.audio2.Audio1._init();
}
diff --git a/Backends/HTML5/kha/audio2/Audio.hx b/Backends/HTML5/kha/audio2/Audio.hx
index e659e21b3..3ef780fb9 100644
--- a/Backends/HTML5/kha/audio2/Audio.hx
+++ b/Backends/HTML5/kha/audio2/Audio.hx
@@ -1,14 +1,14 @@
package kha.audio2;
-import js.Syntax;
import js.Browser;
+import js.Syntax;
import js.html.URL;
import js.html.audio.AudioContext;
import js.html.audio.AudioProcessingEvent;
import js.html.audio.ScriptProcessorNode;
+import kha.Sound;
import kha.internal.IntBox;
import kha.js.AEAudioChannel;
-import kha.Sound;
class Audio {
public static var disableGcInteractions = false;
@@ -70,7 +70,7 @@ class Audio {
public static var samplesPerSecond: Int;
- public static var audioCallback: kha.internal.IntBox->Buffer->Void;
+ public static var audioCallback: (outputBufferLength: IntBox, buffer: Buffer) -> Void;
static var virtualChannels: Array = [];
diff --git a/Sources/kha/System.hx b/Sources/kha/System.hx
index 1d4bd1dc5..37066c1ae 100644
--- a/Sources/kha/System.hx
+++ b/Sources/kha/System.hx
@@ -2,24 +2,33 @@ package kha;
import kha.WindowOptions;
+@:structInit
+private class AudioOptions {
+ /** Allow `audio2.Audio` api initialization on mobile browsers (only for HTML5 target) **/
+ public var allowMobileWebAudio = false;
+}
+
@:structInit
class SystemOptions {
- @:optional public var title: String = "Kha";
- @:optional public var width: Int = -1;
- @:optional public var height: Int = -1;
- @:optional public var window: WindowOptions = null;
- @:optional public var framebuffer: FramebufferOptions = null;
+ public var title: String = "Kha";
+ public var width: Int = -1;
+ public var height: Int = -1;
+ public var window: WindowOptions = null;
+ public var framebuffer: FramebufferOptions = null;
+ public var audio: AudioOptions = null;
/**
- * Used to provide parameters for System.start
+ * Used to provide parameters for `System.start`
* @param title The application title is the default window title (unless the window parameter provides a title of its own)
* and is used for various other purposes - for example for save data locations
- * @param width Just a shortcut which overwrites window.width if set
- * @param height Just a shortcut which overwrites window.height if set
+ * @param width Just a shortcut which overwrites `window.width` if set
+ * @param height Just a shortcut which overwrites `window.height` if set
* @param window Optionally provide window options
* @param framebuffer Optionally provide framebuffer options
+ * @param audio Optionally provide audio options
*/
- public function new(title: String = "Kha", ?width: Int = -1, ?height: Int = -1, window: WindowOptions = null, framebuffer: FramebufferOptions = null) {
+ public function new(title: String = "Kha", ?width: Int = -1, ?height: Int = -1, ?window: WindowOptions, ?framebuffer: FramebufferOptions,
+ ?audio: AudioOptions) {
this.title = title;
this.window = window == null ? {} : window;
@@ -44,6 +53,7 @@ class SystemOptions {
}
this.framebuffer = framebuffer == null ? {} : framebuffer;
+ this.audio = audio ?? {};
}
}
diff --git a/Sources/kha/audio2/Audio.hx b/Sources/kha/audio2/Audio.hx
index f427ca4cf..598ca7e86 100644
--- a/Sources/kha/audio2/Audio.hx
+++ b/Sources/kha/audio2/Audio.hx
@@ -1,5 +1,7 @@
package kha.audio2;
+import kha.internal.IntBox;
+
extern class Audio {
/**
* The samples per second natively used by the target system.
@@ -10,8 +12,10 @@ extern class Audio {
* Requests additional audio data.
* Beware: This is called from a separate audio thread on some targets.
* See kha.audio2.Audio1 for sample code.
+ * This api is disabled on mobile for HTML5 target by default
+ * and can be enabled in `System.start` options.
*/
- public static var audioCallback: Int->Buffer->Void;
+ public static var audioCallback: (outputBufferLength:IntBox, buffer:Buffer)->Void;
/**
* Similar to kha.audio1.Audio.stream, but only for hardware accelerated audio playback.