refactor audio startup so it will autostart on firefox, if allowed

This commit is contained in:
Jakob Ketterl
2020-08-23 17:56:13 +02:00
parent 6aa25760c5
commit 9e41d49d46
2 changed files with 127 additions and 101 deletions

View File

@ -1099,9 +1099,11 @@ var mute = false;
// Optimalise these if audio lags or is choppy:
var audio_buffer_maximal_length_sec = 1; //actual number of samples are calculated from sample rate
function onAudioStart(success, apiType){
function onAudioStart(apiType){
divlog('Web Audio API succesfully initialized, using ' + apiType + ' API, sample rate: ' + audioEngine.getSampleRate() + " Hz");
hideOverlay();
// canvas_container is set after waterfall_init() has been called. we cannot initialize before.
//if (canvas_container) synchronize_demodulator_init();
@ -1320,11 +1322,12 @@ var audioEngine;
function openwebrx_init() {
audioEngine = new AudioEngine(audio_buffer_maximal_length_sec, audioReporter);
$overlay = $('#openwebrx-autoplay-overlay');
$overlay.on('click', playButtonClick);
$overlay.on('click', function(){
audioEngine.resume();
});
audioEngine.onStart(onAudioStart);
if (!audioEngine.isAllowed()) {
$overlay.show();
} else {
audioEngine.start(onAudioStart);
}
fft_codec = new ImaAdpcmCodec();
initProgressBars();
@ -1370,9 +1373,7 @@ function update_dmr_timeslot_filtering() {
$('#openwebrx-panel-receiver').demodulatorPanel().getDemodulator().setDmrFilter(filter);
}
function playButtonClick() {
//On iOS, we can only start audio from a click or touch event.
audioEngine.start(onAudioStart);
function hideOverlay() {
var $overlay = $('#openwebrx-autoplay-overlay');
$overlay.css('opacity', 0);
$overlay.on('transitionend', function() {