Reputation: 8640
Audio file can not play in Safari.. It gives an Error.
TypeError: 'undefined' is not a function (evaluating 'myAudio.play()')
Here is my HTML code.
<audio>
<source src="audio/horse.ogg" type="audio/ogg">
<source src="audio/horse.mp3" type="audio/mpeg">
Your browser does not support the audio element.
</audio>
Here is my JavaScript Code
myAudio = document.getElementsByTagName('audio')[0];
if (typeof myAudio.loop == 'boolean'){
myAudio.loop = true;
}
else{
myAudio.addEventListener('ended', function() {
this.currentTime = 0;
this.play();
}, false);
}
myAudio.play();
I have only One Audio Tag in HTML.
Upvotes: 1
Views: 3786
Reputation: 169
It will never work on Windows Safari because the last Safari for Windows was released in 2010. And that's the reason why HTML5: <audio>
or <video>
tags does not work in Windows Safari. Test yourself
Upvotes: 1
Reputation: 1477
I had similar problem on my windows pc.
So to test, I created a simple HTML file with one red big dot and clicking which would play the audio. It worked on all HTML5 compatible browsers EXCEPT safari. I spent whole day and tried more than 100 different solutions to get it to work on on safari, but no luck.
At the end, I installed QuickTime (latest version) and it solved 50% of the problem.
Rest 50% of the problem was the code structure.
<audio id="audio1" src="audio/guestProfile.ogg" type="audio/ogg" ></audio>
<audio id="audio1" src="audio/guestProfile.mp3" type="audio/mpeg" ></audio>
It didn't like the above code. So I had to change it to following:
<audio id="audio1">
<source src="audio/guestProfile.ogg" type="audio/ogg">
<source src="audio/guestProfile.mp3" type="audio/mpeg">
Your browser does not support the audio tag.
</audio>
This may not be the neat & perfect solution. But it worked for me.
Upvotes: 1