Skip to content

Pass custom parameter into icecast-metadata-player-1.17.1.main.min.js #195

Description

@blantonl

How can I pass a custom int parameter into the script that is available globally from the configuration of the instance?

I'm trying to display the currently received volume for a stream - the below implementation logs it to the console. Ideally this would be implemented as a callback that could update labels or canvases for multiple players on a single page with the currently received audio volume.

I'm attempting to add the following code which allows for adding a web audio analyzer connects to the chain that calculates the volume currently received

                  const scriptNode = e.createScriptProcessor(16384, 2, 2);
                  const myAudio = document.querySelector("audio");
                  const source = e.createMediaElementSource(myAudio);
                  const analyser = e.createAnalyser();
                  source.connect(analyser);
                  analyser.connect(e.destination);
                  scriptNode.connect(e.destination),
                      (e.onstatechange = () => {
                          "running" !== e.state && e.resume().catch(t);
                      });
                  
                  analyser.fftSize = 2048;

                  const sampleBuffer = new Float32Array(analyser.fftSize);
                  setInterval(function() {
                      analyser.getFloatTimeDomainData(sampleBuffer);
                      // Compute average power over the interval.
                      let sumOfSquares = 0;
                      for (let i = 0; i < sampleBuffer.length; i++) {
                          sumOfSquares += sampleBuffer[i] ** 2;
                      }
                      const avgPowerDecibels = 10 * Math.log10(sumOfSquares / sampleBuffer.length);

                      // Compute peak instantaneous power over the interval.
                      let peakInstantaneousPower = 0;
                      for (let i = 0; i < sampleBuffer.length; i++) {
                          const power = sampleBuffer[i] ** 2;
                          peakInstantaneousPower = Math.max(power, peakInstantaneousPower);
                      }
                      const peakInstantaneousPowerDecibels = 10 * Math.log10(peakInstantaneousPower);
                      console.log(avgPowerDecibels.toFixed(2));
                  }, 1000);
              })

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions