Closed heaversm closed 7 years ago
Realized this is an issue with html5 audio api itself, not oscilloscope. I should be using createMediaElementSource
instead of createMediaStreamSource
. Closing.
Hi, I was just going through some old code, but I only found loading audio through ajax. If you have an example of how to do it with html5 audio, it could be nice to add it to the readme 😃
Cool - yeah - here's how I did it. I'm using the twilio API, so my voice recordings are coming from there. Init as normal, with the only difference being the:
initScope = function () {
context = new window.AudioContext()
canvas = document.querySelector('.visualizer')
audio = document.querySelector('.audio') //or audio = $('.audio')[0] if using jQuery
var options = {
stroke: 1, // size of the wave
buffer: 1024 // buffer size ranging from 32 to 2048
}
scope = new Oscilloscope(canvas, options)
var source = context.createMediaElementSource(audio) //create media element source on your audio html element
scope.addSignal(source, '#ffffff')
}
Then I also had to add a crossOrigin property to the audio element because it was coming from twilio to prevent getting access restrictions:
audio.crossOrigin = "anonymous"
Hi! Just wondering if there's a way to load an html5 audio source as the source for the oscilloscope instead of a get user media stream? I currently get this error: