music-visualizer | web audio api to create an audio visualizer | Audio Utils library
kandi X-RAY | music-visualizer Summary
kandi X-RAY | music-visualizer Summary
Played around with the Web Audio API to create an audio visualization. (HTML5 + JS).
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Renders the frames
music-visualizer Key Features
music-visualizer Examples and Code Snippets
Community Discussions
Trending Discussions on music-visualizer
QUESTION
Context: I'm trying to create an audio visualizer using the Web Audio API with createMediaElementSource() very similarly to the model explained in this tutorial. The hosting service my client is using for their audio inserts a 302 redirect before the actual media, to track listening data.
Problem: In Safari, when I attach an AudioContext to an audio element that is linked to a source with a 302 redirect in front of it, it outputs silence instead of normal audio without any errors in the log. By contrast I've tested Chrome and Firefox, and they both work fine with no issues.
In the demo above, all three buttons attach and play the same audio source, but in the second and third it goes through the redirect first. The second attaches an AudioContext as well, while the third just plays the audio normally with no visual.
I posted about this issue last month and it was suggested that the problem was some missing CORS headers on the 302 redirect. However, I am now testing my own redirect server instead of using the hosting service, so that I can test my own CORS rules (see below). The issue remains even with these headers set, so this makes me think it's a bug in Safari with 302 redirects. What I'd like to know is A) Are there any other cross origin headers I can try adding that may resolve the issue, and B) If it is indeed a Safari bug, where do I go to report it and how long from that point until someone addresses it.
Headers I've set for my 302 redirect:
...ANSWER
Answered 2020-Jul-30 at 18:53Update: I've now reported this as a bug, and the Webkit devs have isolated the check causing the issue.
QUESTION
I'm trying to create an audio visualization for a podcast network, using the Web Audio API with createMediaElementSource() very similarly to the model explained in this tutorial. So far I've gotten it to work fine in Chrome, and you can see it here (note: click on the red box to start it).
Update: Based on discussion in the comments, it’s now become clear that the problem happens because the request gets redirected to another URL, by way of a 302 redirect.
However, Safari refuses to work, outputting no sound and producing no visualization although it shows the track playing. I believe it has to do with the CORS policy of the server I'm requesting the audio from, because I've alternatively tried using this audio source and it works great in all browsers. My suspicion is it's an issue arising due to this standard of the web audio API.
The fact that it only happens in safari makes me pray that there's some easy syntactic solution either on my end or the server host's end in their CORS policy to get this to work. I'm hoping someone can point out exactly what's going wrong in the header requests/responses that's causing this problem. Let me know if there's any more information I need to provide. I've left a simplified version of my AudioContext code below in case a problem surfaces there.
...ANSWER
Answered 2020-Jul-08 at 01:46Short answer: The maintainers of the service sending the 302
response to your request should update their backend config such that it adds the Access-Control-Allow-Origin
header to 302
responses (and any other 3xx
redirect responses) — not just to 200
OK responses.
If you can’t get them to do that, then basically you only have exactly two other options:
- Change your frontend code to make the request through a CORS proxy; or else
- Don’t make the request from your frontend code at all, but instead do it completely from your backend server-side code (where the same-origin policy doesn’t apply).
Explanation
Here’s what happens:
Your frontend code makes a request to a
https://rss.art19.com/episodes/….mp3
URL.The
https://rss.art19.com
server replies to with a302
redirect response that has aLocation: https://content.production.cdn.art19.com/…episodes/….mp3
header.The browser receives that
302
response and checks the response headers to see if there’s anAccess-Control-Allow-Origin
header. If there isn’t, the browser blocks your code from accessing the response from thehttps://content.production.cdn.art19.com/….mp3
redirect URL. Instead the browser will stop and throw an exception.
You can sometimes fix this problem by taking the redirect URL and using it as the request URL in your frontend code. For example, rather than using https://rss.art19.com/episodes/….mp3
in your code, use https://content.production.cdn.art19.com/…episodes/….mp3
— since the 200 OK
response from that URL does include the Access-Control-Allow-Origin
header).
But in many or most cases in practice, that strategy won’t work — because it’s not feasible to preemptively identify what the redirect URL will be.
Note that, by design, browsers intentionally don’t expose redirect URLs to frontend code. So it’s impossible from frontend code to programatically get a redirect URL and do another request with it.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install music-visualizer
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page