Reputation: 569
I have a website and need to play an audio file with JavaScript using
var audio = new Audio(file);
audio.play();
Unfortunatly, the web-space host doesn't allow to upload mp3 files. Can I play a file stored at my google drive account somehow
Upvotes: 2
Views: 3552
Reputation: 2403
If you are working with HTML5 you can use Direct Link Creator plugin of Google Drive and get the link easily. Here's an example.
<audio controls="controls">
<source src="https://docs.google.com/uc?export=download&id=0B_ETxiqrp0SzbF9VQ3JCS2hnSlU">
</audio>
<video controls="controls">
<source src="https://drive.google.com/uc?export=download&id=0B0JMGMGgxp9WMEdWb1hyQUhlOWs" type='video/mp4' />
</video>
If you don't want to mess with HTML elements:
var audio = new Audio('audio_file.mp3');
audio.play();
This uses the HTMLAudioElement
interface, which plays audio the same way as the <audio>
element.
If you need more functionality, use the howler.js library and found it simple and useful.
Upvotes: 3