Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Audio element not working properly with Safari

I can't seem to get the audio element to work properly in Safari (v 5.1.2). I've tried moving the file to the same folder as the page, using both mp3 and mpeg MIME types, and changing filenames. It seems to work fine in all other browsers, but in Safari the audio element is created, but only shows that it is loading and will not play. Any ideas?

<audio controls preload="metadata">
  <source src="audio/song.mp3" type="audio/mpeg" />
  <source src="audio/song.ogg" type="audio/ogg" />
</audio>

Thanks

like image 813
bgmaster Avatar asked Dec 31 '11 18:12

bgmaster


2 Answers

Does your website use an invalid HTTPS certificate or a HTTP Auth? I had this issue but found that Safari was having issues with either my invalid HTTPS cert or the Basic Auth (on the staging server).

like image 119
Kizer Avatar answered Nov 08 '22 18:11

Kizer


Safari does not seem to load sounds reliably with preload="metadata".

You can try this in the console, of any webpage really:

var snd = document.createElement('audio'), src = document.createElement('source');
src.src = "http://www.largesound.com/ashborytour/sound/brobob.mp3";
src.type = "audio/mpeg";
snd.appendChild(src);
snd.preload = 'metadata';
snd.play();

It doesn't work. Then:

snd.preload = null;   // equivalent to 'auto'

And voilà! It starts playing.

(I've filed this as rdar://problem/11481585, not that that helps any of us.)

like image 25
natevw Avatar answered Nov 08 '22 20:11

natevw