How to use background music?
onigoshi
06 Apr 2017, 19:52Hi, im completely new at this, i only started yesterday but made some nice progress so far. But i wanna know how to put background music to play. I have no idea of how to do it. I want to play some musics in MP3 format. How can i do this?
![](https://i.imgur.com/mpaalk0b.jpg)
manowar
08 Apr 2017, 08:57This works for me. If you dont like the music repeat only quit the addEventListener line. If you want stop the music myAudio.stop(); maybe works. In the Loss.mp3 you can place the url of the music file.
@start Init
[[Init]]:
var myAudio = new Audio('Loss.mp3');
myAudio.addEventListener('ended', function() {this.currentTime = 0; this.play();}, false);
myAudio.play();
Hello world!
Bond, James bond
05 Jun 2017, 08:52but where should I put my music in ur code?
@start Init
[[Init]]:
var myAudio = new Audio('Loss.mp3');
myAudio.addEventListener('ended', function() {this.currentTime = 0; this.play();}, false);
myAudio.play();
and what should I put inside these () ?
and how can I take music lets say from you tube and play it here as a background?
can u put an actual example of a code that if copied it, it will play in the background of our game?