1

I am using the javascript Audio object to play an mp3

var myAudio = new Audio('alarm.mp3');
myAudio.play();

This works fine if I don't have a dialog. But if I add one

var response = confirm("press ok if you are awake");

Then playback stops until I close the dialog window. Is there a way to prevent playback from being stopped by a dialog?

ekcrisp
  • 1,967
  • 1
  • 18
  • 26
  • 1
    provide a fiddle please – zzlalani Jan 30 '14 at 07:22
  • maybe also browser-dependent behaviour – Thilo Jan 30 '14 at 07:23
  • I've discovered that if i create the audio using `var myAudio = new Audio('alarm.mp3');` then the code doesn't work, however if I have an audio tag in my html with src attribute "alarm.mp3", and i instead use var `myAudio1 = document.getElementById("audio1");` then it works the way I want, any ideas why that is? – ekcrisp Jan 30 '14 at 17:32
  • I have made a new question for this issue, see http://stackoverflow.com/questions/21463752/javascript-audio-object-vs-html5-audio-tag – ekcrisp Jan 30 '14 at 17:53
  • Do you need to use a dialogue? – Damian Silva Nov 23 '15 at 22:47

0 Answers0