So I am making an audio visualization website and I thought it would be cool if I could actually have the user paste a youtube video url into the site, and the site would use the source url of that youtube video as the source for the html5 audio tag (html5 audio supports mp4). But for some reason, it just doesn't wanna work.
As it stands now, when I try to do it, I get the error "MediaElementAudioSource outputs zeros due to CORS access restrictions". So, since I've read up on this issue before, I came to the solution that I could just add the attribute: crossOrigin = "anonymous"; to my audio tag, and it would start working.
Nope, it doesn't. Now I get the error "Uncaught (in promise) DOMException: Failed to load because no supported source was found." I am completely stumped.
Also please note that the site works perfectly fine right now when the user simply drags audio tracks or mp4 videos onto the site. I use URL.createObjectURL() to create a url of the file dragged on.
Any help would be greatly appreciated, thanks.
edit1: So I did some more research and I came upon an article, HTMLMediaElement.play() Returns a Promise, and so I put together some code
var audio = document.getElementById("myAudio");
audio.crossOrigin = "anonymous";
audio.src = songSources[currentIndex];
audio.load();
var playPromise = audio.play();
if (playPromise !== undefined) {
playPromise.then(function() {
alert("good");
}).catch(function(error) {
alert(error);
});
}
and as I sorta expected I got an error message, from the catch block. It read: "NotSupportedError: Failed to load because no supported source was found." This I find extremely confusing because the audio element will play fine if I simply remove the crossOrigin="anonymous" attribute from it. Any ideas?
edit2: Seems as though I've also stumped you guys, lol.