Reset Audio file
I am make a music visualizer. When the user decides to load a new song, the current song that is playing should stop, and the new song should play.
here is my code for the audio part:
var tmp = document.getElementById("mainsvg");
var stream,newaudio,analyser, width = tmp.clientWidth,dx, dy,
height = tmp.clientHeight,audioSRC;
var audioCTX = new (window.AudioContext || window.webkitAudioContest)();
var audio = document.getElementById("audiofile");
if (audio){
audio.value="";
}
audio.addEventListener("change", function(event){
stream = URL.createObjectURL(event.target.files[0]);
newaudio = new Audio();
newaudio.src=stream;
newaudio.addEventListener('canplay', function () {
audioSRC = audioCTX.createMediaElementSource(newaudio);
analyser = audioCTX.createAnalyser();
audioSRC.connect(analyser);
audioSRC.connect(audioCTX.destination);
newaudio.play();
callfirst();
});
});
however, when i run this code. The old song still plays along with the new selected song. How do i fix this?
Posted Sep 16, 2015, 6:27 AM UTC
10