依稀往事

导航

HTML网页音频控制


// 音频播放
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; 

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" );

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("您的浏览器不支持要检测的音频格式。");

posted on 2018-05-12 20:18  依稀往事  阅读(326)  评论(0编辑  收藏  举报