Created
February 28, 2018 18:22
-
-
Save pngan/c022c1c2152d27fd55a580bf3e4d872a to your computer and use it in GitHub Desktop.
Download audio using javascript and playing in an audio instance
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <html> | |
| <head> | |
| <script> | |
| var xhr = new XMLHttpRequest(); | |
| xhr.open("GET", "https://pn.tpagent.eilabonline.biz:8957/api/v1/recordingstream/audios/57defc71-6faf-4c98-95fb-06fe1b6acb92"); | |
| xhr.setRequestHeader("Authorization", "Bearer <token>"); | |
| xhr.responseType = 'blob'; | |
| xhr.onreadystatechange = function() { | |
| if (xhr.readyState == 4 && xhr.status == 200) { | |
| console.log("got data"); | |
| var audio = document.getElementById('target'); | |
| audio.src = URL.createObjectURL(xhr.response); | |
| audio.play(); | |
| } | |
| }; | |
| xhr.send(null); | |
| </script> | |
| </head> | |
| <body> | |
| <audio id="target" controls /> | |
| </body> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment