+ 1
Why is loading taking so long and how to fix it?
Why is loading taking so long and how to fix it? https://code.sololearn.com/W9z7CSgGSk7l/?ref=app
2 odpowiedzi
+ 2
I see some behaviour that changes different times I run it. I'm not sure why.
When I first ran it, it never finished "loading". I checked developer tools and saw this response to your heroku cors-anywhere request:
------------------------------------------------------------------------------------
Google
We're sorry...
... but your computer or network may be sending automated queries. To protect our users, we can't process your request right now.
See Google Help for more information.
-------------------------------------------------------------------------
It looked like Google Drive doesn't want to play nice with Heroku's service. You could try relaying the request using one of your own servers. That might work. It might be working some of the time if Google doesn't recognize Heroku's IP address as something to block.
Aside from the heroku cors-anywhere server IP changing, I did something else that might have caused it to load. I downloaded the music direct from https://drive.google.com/uc?export=view&id=1-BuJ0SjmbdSiZmD5NQ7kkKQujnHYV36x. After downloading from https://drive.google.com/uc?export=view&id=1-BuJ0SjmbdSiZmD5NQ7kkKQujnHYV36x, it ran fine every time. I'm not sure if local cache is involved.
If you just want to play your mp3, you could use this to add a control to play it:
<audio controls="" autoplay="" name="media">
<source src="https://drive.google.com/uc?export=view&id=1-BuJ0SjmbdSiZmD5NQ7kkKQujnHYV36x" type="audio/mpeg">
</audio>
Also, without the user hitting a play button and without relaying an HTTP request through a CORS-anywhere proxy, you could have JavaScript play the sound. You will, however, need to get the user to click on the page or somehow indicate focus on the page. Most web browsers won't let audio play until the user interacts with the page somehow.
This should do the trick:
var audio = new Audio();
audio.src = 'https://drive.google.com/uc?export=view&id=1-BuJ0SjmbdSiZmD5NQ7kkKQujnHYV36x';
audio.play();
0
Thank you very much Josh. I decided to use Howler because I wanted to play a music in the start menu of the game. Could you give me idea about this?
https://code.sololearn.com/WOV9ecWz7302/?ref=app