+ 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

30th Oct 2020, 11:42 AM
IlyaVerem
IlyaVerem - avatar
2 Antworten
+ 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();
31st Oct 2020, 8:02 AM
Josh Greig
Josh Greig - avatar
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
2nd Nov 2020, 6:30 AM
IlyaVerem
IlyaVerem - avatar