I have this html and js which I'm using to play some audio:
HTML
<div id="audio-clips">
<audio src="/audio/cha-ching.wav" type="audio/wav" id="audio-cha-ching">
</div>
JavaScript
var sfx = $("#audio-clips #audio-cha-ching")[0];
sfx.play();
This is failing in IE 8, due to it not recognising the "play" method. Is there a jQuery audio-playing method which works cross-browser, with the same code? I'd rather do that then try to fall back to some IE-specific solution (as browser-specific solutions are always brittle).
I have this html and js which I'm using to play some audio:
HTML
<div id="audio-clips">
<audio src="/audio/cha-ching.wav" type="audio/wav" id="audio-cha-ching">
</div>
JavaScript
var sfx = $("#audio-clips #audio-cha-ching")[0];
sfx.play();
This is failing in IE 8, due to it not recognising the "play" method. Is there a jQuery audio-playing method which works cross-browser, with the same code? I'd rather do that then try to fall back to some IE-specific solution (as browser-specific solutions are always brittle).
Share Improve this question edited Oct 15, 2012 at 11:26 Fenton 252k73 gold badges402 silver badges409 bronze badges asked Oct 15, 2012 at 11:16 Max WilliamsMax Williams 33k34 gold badges135 silver badges204 bronze badges 1- 2 As far as I have read in various blogs , the only way to make audio work in IE8 is to have a flash fallback. You could try schillmania./projects/soundmanager2 which provides a flash fallback when html audio is not supported – Harsha Venkataramu Commented Oct 15, 2012 at 11:18
4 Answers
Reset to default 3I would strongly remend using howler.js for playing audio files. It has great patibility across browsers and devices. It uses HTML5 audio when available, and falls back to older technologies when necessary.
HTML5 support on IE started on IE9 :(.
By the way, I am not sure if WAV is played by IE(I would not say so): http://en.wikipedia/wiki/HTML5_Audio
Fallback solution for HTML and legacy browsers
The audio
tag is available in Internet Explorer 9 and above. You can check this using Can I Use - Audio.
The wav
format is supported by Firefox 3.6+, Safari 5+, Opera 10.5+ and Internet Explorer 9+ on the audio tag. You would need to add an MP3
source in addition to the wav
source to get Chrome support.
To get backwards patible support, you use the following - Flash element omitted for brevity.
<audio controls preload="auto" autobuffer>
<source src="sound.mp3" />
<source src="sound.ogg" />
<source src="sound.wav" />
<!-- now include flash fall back -->
</audio>
Encode your audio in mp4 format, instead of wav. This works for me in IE 11.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744305551a4567714.html
评论列表(0条)