Closed 808y closed 1 year ago
Can you share how you are instantiating IcecastMetadataPlayer
?
You should be able to attach the Audio element (either the one created internally or on that you pass into the options) to an AudioContext instance and then attach your analyzer node there.
Here's an example of how I attach the Audio element as a source to an AudioContext so I can show visualizers on the demo: https://github.com/eshaz/icecast-metadata-js/blob/7c234e44f9a361b92c83203b9e03b4177ecf7a21/src/demo/src/Visualizer/Visualizer.jsx#L42-L47
This may only work using the mediasource
playback method, but that should be fine unless you want your project to support iOS.
OK thanks for your answer i'll try mediasource (makes sense to use that method) i used webaudio as playback method for IcecastMetadataPlayer ...
so now it works!
const player = new IcecastMetadataPlayer()
analyser = audioContext.createAnalyser();
analyser.fftSize = 2048;
const source = audioContext.createMediaElementSource(player.audioElement);
source.connect( analyser );
analyser.connect( audioContext.destination );
updatePitch();
Awesome, glad it's working for you!
hi there! i'm trying to get an icecast stream analysed with webaudio (pitch detection) but i cannot get it working audioContext = new AudioContext(); analyser = audioContext.createAnalyser(); analyser.fftSize = 2048; sourceNode = audioContext.createMediaStreamSource(audioElement); sourceNode.connect( analyser );
got a 'TypeError: this.xi.createMediaStreamDestination is not a function'
how should i declare audioElement ?