// 音頻播放
function playSound(url)
{
var borswer = window.navigator.userAgent.toLowerCase();
var audio;
if ( borswer.indexOf( "ie" ) >= 0)
{
//IE8及以前版本,測試過,貌似無效
var strEmbed = '<embed name="embedPlay" src="' + url + '" autostart="true" hidden="true" loop="false" volume="60"></embed>';
if ( $( "body" ).find( "embed" ).length <= 0 )
$( "body" ).append( strEmbed );
var embed = document.embedPlay;瀏覽器
embed.volume = 100; app
audio = embed;
} else
{
//非IE內核瀏覽器
var strAudio = "<audio id='audioPlay' src='" + url + "' hidden='true'>";
if ( $( "body" ).find( "audio" ).length <= 0 )
$( "body" ).append( strAudio );
audio = document.getElementById( "audioPlay" );oop
audio.play();
audio.volume = 1;
}
return audio;
}測試
/* 檢查網站適用那種音頻格式 */
function checkAudio(){
var myAudio = document.createElement('audio');
myAudio.ip = "examAudio191199846061";
var info = "";
if (myAudio.canPlayType) {
if ( "" != myAudio.canPlayType('audio/mpeg')) {
info = "您的瀏覽器支持mp3編碼、";
}網站
if ( "" != myAudio.canPlayType('audio/ogg;codecs="vorbis"')) {
info += "oog編碼、";
}編碼
if ( "" != myAudio.canPlayType('audio/mp4;codecs="mp4a.40.5"')) {
info += "aac編碼";
}
alert(info);
}else {
alert("您的瀏覽器不支持要檢測的音頻格式。");url