I'm working on a website that has a chat for a client, however, we're experiencing problems with audio in iPad (iOS 5).
The target is in fact the iPad with support for IE7 is preferred.
I've tried these approaches:
HTML5
<audio id="notification" preload="auto">
<source src="audio/notification.ogg" type="audio/ogg" />
<source src="audio/notification.mp3" type="audio/mpeg" />
</audio>
With some javascript
var el = document.getElementById('notification');
el.play();
Some javascript function I stole somewhere which in fact are two different methods in one function. Please note the script is in a subdir, so the path is correct.
function notify() {
var url = '../audio/notification.mp3';
var a = document.createElement('audio');
if(!!(a.canPlayType && a.canPlayType('audio/mpeg').replace(/no/, ''))) {
var sound = new Audio(url);
sound.load();
sound.play();
} else {
$('#notification').remove();
var sound = $('<embed id="notification" type="audio/mpeg" src="'+url+'" loop="false" hidden="true" autostart="true" />');
$(body).append(sound);
}
}
Both methods doesn't seem to work. Am I doing something wrong?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…