From 182821e037b6fe65833ceb203480029c3672d15a Mon Sep 17 00:00:00 2001 From: ehpersonal38 <103586016+ehpersonal38@users.noreply.github.com> Date: Fri, 20 May 2022 13:08:40 -0400 Subject: [PATCH] Use "Live Audio" stream in top right if running Prevents duplicate audio sources --- scripts/spectrogram.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/scripts/spectrogram.php b/scripts/spectrogram.php index abfc81a..7ae4b1e 100644 --- a/scripts/spectrogram.php +++ b/scripts/spectrogram.php @@ -4,7 +4,17 @@ // UPDATE: there is a problem in chrome with starting audio context // before a user gesture. This fixes it. var started = null; +var player = null; window.onload = function(){ + var audioelement = window.parent.document.getElementsByTagName("audio")[0]; + if (typeof(audioelement) != 'undefined') { + + document.getElementById('player').remove(); + + player = audioelement; + } else { + player = document.getElementById('player'); + } if (started) return; started = true; initialize(); @@ -25,7 +35,7 @@ function initialize() { process(); function process() { - const SOURCE = ACTX.createMediaElementSource(document.getElementById('player')); + const SOURCE = ACTX.createMediaElementSource(player); SOURCE.connect(ANALYSER); SOURCE.connect(ACTX.destination) const DATA = new Uint8Array(ANALYSER.frequencyBinCount); @@ -79,6 +89,7 @@ h1 { } +