Forum Discussion

alexalberto's avatar
alexalberto
Community Member
3 years ago

Why doesn't music play automatically when project starts with java?

With the following java code, the music does not play in the background when the first slide is opened. There is a sound on the next slides, but if a button is clicked, this sound starts playing. I didn't manage to automatically play the music when the project was opened. how can i play the music when auto project starts.

//load the scripts dynamically into the head of the document
function add_line() {
 var line = document.createElement("audio");
 var head=document.getElementsByTagName('body')[0];
 line.type = "audio/mp3";
 line.src=" ";
 line.id="bgSong" ;
 line.autoplay = true;
 line.loop = true;
 head.appendChild(line);
}
//but we only want to add these once!
if(document.getElementById('bgSong')==null){
 add_line();
var audio = document.getElementById('bgSong');
audio.volume = 1.0;
}

var player = GetPlayer();
var audio = document.getElementById('bgSong');
this.Location= player.GetVar("location");

if (audio.duration > 0 && !audio.paused) {
// If song is playing and not paused then do nothing
}
else {
audio.src=Location+"02 Phir Bhi Tumko Chahunga - Half Girlfriend (Arijit Singh) 320Kbps.mp3"; 
audio.load();
audio.play();
}

No RepliesBe the first to reply