我试图在Opera 12.16(最新版本)和I noticed it doesn't work with mp3
files中播放audio
元素,但它与ogg
一起播放。Opera中的声音提示
这里是我的小提琴目前只适用于MP3文件和歌剧不工作: http://jsfiddle.net/hMnsd/1/
的解决方案似乎做这样的事情(如指向w3c website):
<audio controls>
<source src="horse.ogg" type="audio/ogg">
<source src="horse.mp3" type="audio/mpeg">
Your browser does not support the audio tag.
</audio>
我使用现在这个功能产生声音:
function notificationSound(){
var audioElement = document.createElement('audio');
audioElement.setAttribute('src', "http://"+ document.domain +"/files/notification2.mp3");
audioElement.setAttribute('type', 'audio/mpeg');
audioElement.setAttribute('autoplay', 'autoplay');
//audioElement.load()
audioElement.addEventListener("load", function() {
audioElement.play();
}, true);
}
为了增加ogg
f ILE我试着不产生所需的结构成功:
var audioElement = document.createElement('audio');
var audioSource1 = document.createElement('source');
var audioSource2 = document.createElement('source');
//mp3 file
audioSource1.setAttribute('src', "http://"+ document.domain +"/files/notification2.mp3");
audioSource1.setAttribute('type', 'audio/mpeg');
//ogg file
audioSource2.setAttribute('src', "http://"+ document.domain +"/files/notification2.ogg");
audioSource2.setAttribute('type', 'audio/ogg');
audioElement.setAttribute('autoplay', 'autoplay');
audioElement.append(audioSource2); //opera
audioElement.append(audioSource1);
//audioElement.load()
$.get();
audioElement.addEventListener("load", function() {
audioElement.get(0).play();
}, true);
怎么能做到它,使其也工作在Opera与ogg
文件?