浏览器 播放音频(IE,谷歌)

web前端 专栏收录该内容
21 篇文章 0 订阅

if (!!window.ActiveXObject || "ActiveXObject" in window){

alert("是ie");

}else{

alert("不是ie");

}

 

谷歌

<div style="display:none;">
	<video id="yinxiao" autobuffer="true">
	   <source src="plug-in/mp3/smsuccess.wav" >
	</video>
</div>


//提示声音
function f_remind(){
	var yinxiao = document.getElementById('yinxiao') ,tolF1 =0; //总时长
	//播放
	yinxiao.addEventListener("loadedmetadata", function(){
		tolF1 = yinxiao.duration;//获取总时长
	});
	yinxiao.play();
		
}

谷歌,ie

<script type="text/javascript">
playSound();
function playSound(){
      var borswer = window.navigator.userAgent.toLowerCase();
      if ( borswer.indexOf( "ie" ) >= 0 ){
        //IE内核浏览器
        var strEmbed = '<embed name="embedPlay" src="plug-in/mp3/smsuccess.wav" autostart="true" hidden="true" loop="false"></embed>';
        if ( $( "body" ).find( "embed" ).length <= 0 )
          $( "body" ).append( strEmbed );
        var embed = document.embedPlay;

        //浏览器不支持 audion,则使用 embed 播放
        embed.volume = 100;
        //embed.play();这个不需要
      }else{
        //非IE内核浏览器
        var strAudio = "<audio id='audioPlay' src='plug-in/mp3/smsuccess.wav' hidden='true'>";
        if ( $( "body" ).find( "audio" ).length <= 0 )
          $( "body" ).append( strAudio );
        var audio = document.getElementById( "audioPlay" );

        //浏览器支持 audion
        audio.play();
      }
    }
</script>	

谷歌,ie


<div id="audioDiv" style="display: none;"></div>
<a href="javascript:void(0);" onclick="startSound();">播放</a>
<a href="javascript:void(0);" onclick="stopSound();">停止</a>

<script type="text/javascript">

function startSound() {
	var mp3snd = "plug-in/mp3/smsuccess.wav";
	var myaudiohtml = "";
	if (navigator.userAgent.toLowerCase().indexOf("msie") != -1) {
		myaudiohtml += '<embed src="'+mp3snd+'" type=application/x-mplayer2 width="0" height="0" autostart="1"/>';
	
	} else if (navigator.userAgent.toLowerCase().indexOf("firefox") != -1) {
		myaudiohtml += '<object data="'+mp3snd+'" type="application/x-mplayer2" width="0" height="0">';
		myaudiohtml += '<param name="filename" value="'+mp3snd+'">';
		myaudiohtml += '<param name="autostart" value="1">';
		myaudiohtml += '<param name="playcount" value="infinite">';
		myaudiohtml += '</object>';
	
	} else {
		myaudiohtml += '<audio src="'+mp3snd+'" autoplay="autoplay" loop="loop">';
		myaudiohtml += '<object data="'+mp3snd+'" type="application/x-mplayer2" width="0" height="0">';
		myaudiohtml += '<param name="filename" value="'+mp3snd+'">';
		myaudiohtml += '<param name="autostart" value="1">';
		myaudiohtml += '<embed height="2" width="2" src="'+mp3snd+'" pluginspage="http://www.apple.com/quicktime/download/" type="video/quicktime" controller="false" controls="false" autoplay="true" autostart="false" loop="false"><br>';
		myaudiohtml += '</embed></object>';
		myaudiohtml += '</audio>';
	}
	
	document.getElementById("audioDiv").innerHTML = myaudiohtml;

}

function stopSound() {
	document.getElementById("audioDiv").innerHTML = "";
}

</script>

 

  • 1
    点赞
  • 0
    评论
  • 0
    收藏
  • 一键三连
    一键三连
  • 扫一扫,分享海报

©️2021 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值