You might see that the Dropbox Community team have been busy working on some major updates to the Community itself! So, here is some info on what’s changed, what’s staying the same and what you can expect from the Dropbox Community overall.
Forum Discussion
danioyuan
7 years agoNew member | Level 2
CORS Problem when playing Dropbox shared link mp3 file
Hi, I'm trying to use Web Audio to adjust tune of a song. I can play the song through a Dropbox shared link using <audio src="https://www.dropbox.com/s/[my shared link here]?dl=1"></audio> H...
- 7 years ago
I can't speak to the behavior of AudioContext, but for reference, if you just use an audio tag by itself, this does work:
<audio controls src="https://www.dropbox.com/s/sbw9hfghk4pqqiw/Laughter.mp3?dl=1"></audio>
For that kind of link, Dropbox will redirect the client, with the resulting URL containing the proper CORS headers.
If you do need to use AudioContext, it looks like there are two issues:
1) You have to specify crossOrigin, e.g., as covered here.
2) AudioContext apparently won't follow the redirects, so you need to give a direct URL. Dropbox does not officially support this, but it does currently work:
<audio crossorigin="anonymous" src="https://dl.dropboxusercontent.com/s/sbw9hfghk4pqqiw/Laughter.mp3?dl=1"></audio> <script> var audioContext = new (window.AudioContext || window.webkitAudioContext)(); var audioNode = document.querySelector("audio"); var playable = false; window.onload = function() { document.body.addEventListener("click", function() { if (playable) { audioNode.play(); } else { audioNode.addEventListener("loadstart", function(event) { console.log(event.type); }); audioNode.addEventListener("loadedmetadata", function(event) { console.log(event.type); }); audioNode.addEventListener("canplay", function(event) { console.log(event.type); playable = true; audioContext.createMediaElementSource(audioNode).connect(audioContext.destination); audioNode.play(); }); audioNode.load(); } }); } </script>
Again though, this isn't officially supported, so it's subject to change/break without warning, and accordingly I don't recommend you rely on it.
Greg-DB
7 years agoDropbox Staff
I can't speak to the behavior of AudioContext, but for reference, if you just use an audio tag by itself, this does work:
<audio controls src="https://www.dropbox.com/s/sbw9hfghk4pqqiw/Laughter.mp3?dl=1"></audio>
For that kind of link, Dropbox will redirect the client, with the resulting URL containing the proper CORS headers.
If you do need to use AudioContext, it looks like there are two issues:
1) You have to specify crossOrigin, e.g., as covered here.
2) AudioContext apparently won't follow the redirects, so you need to give a direct URL. Dropbox does not officially support this, but it does currently work:
<audio crossorigin="anonymous" src="https://dl.dropboxusercontent.com/s/sbw9hfghk4pqqiw/Laughter.mp3?dl=1"></audio> <script> var audioContext = new (window.AudioContext || window.webkitAudioContext)(); var audioNode = document.querySelector("audio"); var playable = false; window.onload = function() { document.body.addEventListener("click", function() { if (playable) { audioNode.play(); } else { audioNode.addEventListener("loadstart", function(event) { console.log(event.type); }); audioNode.addEventListener("loadedmetadata", function(event) { console.log(event.type); }); audioNode.addEventListener("canplay", function(event) { console.log(event.type); playable = true; audioContext.createMediaElementSource(audioNode).connect(audioContext.destination); audioNode.play(); }); audioNode.load(); } }); } </script>
Again though, this isn't officially supported, so it's subject to change/break without warning, and accordingly I don't recommend you rely on it.
About Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.
5,882 PostsLatest Activity: 11 hours agoIf you need more help you can view your support options (expected response time for an email or ticket is 24 hours), or contact us on X or Facebook.
For more info on available support options for your Dropbox plan, see this article.
If you found the answer to your question in this Community thread, please 'like' the post to say thanks and to let us know it was useful!