实现在线播放Wav音频文件,支持IE和Google

最近在弄一个在线播放Wav音频文件的功能,发现audio只支持在google浏览器下才能访问,ie是不支持的,但是ie支持embed标签的播放。

  getWebIE:function(){
	   var userAgent = navigator.userAgent; //取得浏览器的userAgent字符串
	   var isIE = userAgent.indexOf("compatible") > -1 && userAgent.indexOf("MSIE") > -1; //判断是否IE<11浏览器             
	   var isEdge = userAgent.indexOf("Edge") > -1 && !isIE; //判断是否IE的Edge浏览器
	   if ((userAgent.indexOf('Trident') > -1 && userAgent.indexOf("rv:11.0"))||(userAgent.indexOf("compatible") > -1 && userAgent.indexOf("MSIE") > -1)) {
	 	return true;
	  } //判断是否IE浏览器
	  else{
	  	return false;
	  }
	},
	play:function(index){
		
		var chenck_value="" // 这里是你的wav音频格式的文件的地址
		if(getWebIE()){
			$('#play_content').find('embed').remove();
			var html=""
			$('#play_content').append(html);
			
		}else{
			$('#play_content').find('audio').remove();
			var html = "";
			$('#play_content').append(html);
		}
		
	},

从代码上面看是通过getWebIE来判断当前浏览器是不是IE类型,如果是ie就会在DOM $('#play_content')生成媒体embed格式的音频播放插件。

在界面上显示就是这个样子的

Google

实现在线播放Wav音频文件,支持IE和Google_第1张图片

IE

实现在线播放Wav音频文件,支持IE和Google_第2张图片

你可能感兴趣的:(技术分享)