[HTML5] Fix errors when Mic is not allowed.
This commit is contained in:
parent
a28d5e2be7
commit
eb2152538c
|
@ -189,7 +189,9 @@ Error AudioDriverJavaScript::capture_start() {
|
||||||
lock();
|
lock();
|
||||||
input_buffer_init(buffer_length);
|
input_buffer_init(buffer_length);
|
||||||
unlock();
|
unlock();
|
||||||
godot_audio_capture_start();
|
if (godot_audio_capture_start()) {
|
||||||
|
return FAILED;
|
||||||
|
}
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -41,7 +41,7 @@ extern int godot_audio_is_available();
|
||||||
extern int godot_audio_init(int p_mix_rate, int p_latency, void (*_state_cb)(int), void (*_latency_cb)(float));
|
extern int godot_audio_init(int p_mix_rate, int p_latency, void (*_state_cb)(int), void (*_latency_cb)(float));
|
||||||
extern void godot_audio_resume();
|
extern void godot_audio_resume();
|
||||||
|
|
||||||
extern void godot_audio_capture_start();
|
extern int godot_audio_capture_start();
|
||||||
extern void godot_audio_capture_stop();
|
extern void godot_audio_capture_stop();
|
||||||
|
|
||||||
// Worklet
|
// Worklet
|
||||||
|
|
|
@ -77,28 +77,37 @@ const GodotAudio = {
|
||||||
|
|
||||||
create_input: function (callback) {
|
create_input: function (callback) {
|
||||||
if (GodotAudio.input) {
|
if (GodotAudio.input) {
|
||||||
return; // Already started.
|
return 0; // Already started.
|
||||||
}
|
}
|
||||||
function gotMediaInput(stream) {
|
function gotMediaInput(stream) {
|
||||||
GodotAudio.input = GodotAudio.ctx.createMediaStreamSource(stream);
|
try {
|
||||||
callback(GodotAudio.input);
|
GodotAudio.input = GodotAudio.ctx.createMediaStreamSource(stream);
|
||||||
|
callback(GodotAudio.input);
|
||||||
|
} catch (e) {
|
||||||
|
GodotRuntime.error('Failed creaating input.', e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (navigator.mediaDevices.getUserMedia) {
|
if (navigator.mediaDevices && navigator.mediaDevices.getUserMedia) {
|
||||||
navigator.mediaDevices.getUserMedia({
|
navigator.mediaDevices.getUserMedia({
|
||||||
'audio': true,
|
'audio': true,
|
||||||
}).then(gotMediaInput, function (e) {
|
}).then(gotMediaInput, function (e) {
|
||||||
GodotRuntime.print(e);
|
GodotRuntime.error('Error getting user media.', e);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
if (!navigator.getUserMedia) {
|
if (!navigator.getUserMedia) {
|
||||||
navigator.getUserMedia = navigator.webkitGetUserMedia || navigator.mozGetUserMedia;
|
navigator.getUserMedia = navigator.webkitGetUserMedia || navigator.mozGetUserMedia;
|
||||||
}
|
}
|
||||||
|
if (!navigator.getUserMedia) {
|
||||||
|
GodotRuntime.error('getUserMedia not available.');
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
navigator.getUserMedia({
|
navigator.getUserMedia({
|
||||||
'audio': true,
|
'audio': true,
|
||||||
}, gotMediaInput, function (e) {
|
}, gotMediaInput, function (e) {
|
||||||
GodotRuntime.print(e);
|
GodotRuntime.print(e);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
return 0;
|
||||||
},
|
},
|
||||||
|
|
||||||
close_async: function (resolve, reject) {
|
close_async: function (resolve, reject) {
|
||||||
|
@ -161,12 +170,9 @@ const GodotAudio = {
|
||||||
},
|
},
|
||||||
|
|
||||||
godot_audio_capture_start__proxy: 'sync',
|
godot_audio_capture_start__proxy: 'sync',
|
||||||
godot_audio_capture_start__sig: 'v',
|
godot_audio_capture_start__sig: 'i',
|
||||||
godot_audio_capture_start: function () {
|
godot_audio_capture_start: function () {
|
||||||
if (GodotAudio.input) {
|
return GodotAudio.create_input(function (input) {
|
||||||
return; // Already started.
|
|
||||||
}
|
|
||||||
GodotAudio.create_input(function (input) {
|
|
||||||
input.connect(GodotAudio.driver.get_node());
|
input.connect(GodotAudio.driver.get_node());
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in a new issue