Reputation: 27
How would I properly put a mp3 file into my javascript program. By this I mean can I just type the name of any mp3 file I have saved on my computer or does it have to be mentioned somewhere else in the code.
var sound1 = new Audio('file1.mp3');
So if I declared the variable "sound" to play file1 do I have to tell the program what file1 is. If so, how would I do so.
Upvotes: 1
Views: 3423
Reputation: 290
Replace
var sound1 = new Audio('file1.mp3');
Whit
var sound1 = new Audio('http://example.com/sub/file.mp3');
While you want the adress to be the adress to you'r mp3 file on your server.
You might write a shorted version of the adress if the file on sub folder like this:
var sound1 = new Audio('/sub/file.mp3');
Upvotes: 0
Reputation: 4125
You can use file:///
, and then use the file path of your mp3 file
var sound1 = new Audio('file:///C:/Users/user/file1.mp3');
Upvotes: 1