jPlayer组件与audio标签以及embed 标签

本文介绍了使用jPlayer插件在Bootstrap项目中实现跨平台音频播放的方法。探讨了自动播放限制及不同浏览器支持情况,包括IE8及以下版本的兼容性问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

最近在用bootstrap在做页面,由于可以在PC端与移动设备端均可以展示,其中有个自动提醒的功能,需要播放音频,在网上下载了jPlayer-2.9.2感觉不错,这个插件在几乎支持所有的浏览器,但是对IE8及其以下都不支持了,很无奈。看例子:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<!-- Website Design By: www.happyworm.com -->
<title>Demo : jPlayer as an audio player</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link href="${rootPath}/webpad/js/jPlayer-2.9.2/dist/skin/blue.monday/css/jplayer.blue.monday.min.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="${rootPath}/webpad/js/jPlayer-2.9.2/lib/jquery.min.js"></script>
<script type="text/javascript" src="${rootPath}/webpad/js/jPlayer-2.9.2/dist/jplayer/jquery.jplayer.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
	$("#jquery_jplayer_1").jPlayer({
		ready: function (event) {
			$(this).jPlayer("setMedia", {
				title: "Bubble",
//				mp3: "${rootPath}/webpad/song.mp3",
//				ogg: "${rootPath}/webpad/song.ogg",
//				wav: "${rootPath}/webpad/song.wav",
				m4a: "http://jplayer.org/audio/m4a/Miaow-07-Bubble.m4a",
				oga: "http://jplayer.org/audio/ogg/Miaow-07-Bubble.ogg"
			}).jPlayer("play");//自动开始播放
		},
		swfPath: "${rootPath}/webpad/js/jPlayer-2.9.2/dist/jplayer",
		supplied: "m4a,oga",
		wmode: "window",
		useStateClassSkin: true,
		autoBlur: false,
		smoothPlayBar: true,
		keyEnabled: true,
		remainingDuration: true,
		toggleDuration: true
	});
});
</script>
</head>
<body>
<div id="jquery_jplayer_1" class="jp-jplayer"></div>
<div id="jp_container_1" class="jp-audio" role="application" aria-label="media player">
	<div class="jp-type-single">
		<div class="jp-gui jp-interface">
			<div class="jp-controls">
				<button class="jp-play" role="button" tabindex="0">play</button>
				<button class="jp-stop" role="button" tabindex="0">stop</button>
			</div>
			<div class="jp-progress">
				<div class="jp-seek-bar">
					<div class="jp-play-bar"></div>
				</div>
			</div>
			<div class="jp-volume-controls">
				<button class="jp-mute" role="button" tabindex="0">mute</button>
				<button class="jp-volume-max" role="button" tabindex="0">max volume</button>
				<div class="jp-volume-bar">
					<div class="jp-volume-bar-value"></div>
				</div>
			</div>
			<div class="jp-time-holder">
				<div class="jp-current-time" role="timer" aria-label="time">&nbsp;</div>
				<div class="jp-duration" role="timer" aria-label="duration">&nbsp;</div>
				<div class="jp-toggles">
					<button class="jp-repeat" role="button" tabindex="0">repeat</button>
				</div>
			</div>
		</div>
		<div class="jp-details">
			<div class="jp-title" aria-label="title">&nbsp;</div>
		</div>
		<div class="jp-no-solution">
			<span>Update Required</span>
			To play the media you will need to either update your browser to a recent version or update your <a href="http://get.adobe.com/flashplayer/" target="_blank">Flash plugin</a>.
		</div>
	</div>
</div>
</body>

</html>

 这个例子可以实现自动播放(想手动播放把jPlayer("play");方法去掉即可),但是仅仅在PC端的,如果在你移动端则必须要用手去点击以下,否则无法播放。这是由于移动设备的安全机制导致的,这一点无法克服。但是这个组件是最接近移动设备的组件了。总之现在还没有一个可以在移动设备自动播放音乐的组件。

 

 

或许有的人会说html5的audio 标签 ,但是这个标签对IE只能支持IE9以上,并且在移动设备端根本无法播放音乐。

实例

<audio controls="controls">
  <source src="song.ogg" type="audio/ogg">
  <source src="song.mp3" type="audio/mpeg">
Your browser does not support the audio tag.
</audio>

亲自试一试

Internet Explorer

Internet Explorer 8 不支持 audio 元素。在 IE 9 中,将提供对 audio 元素的支持。

<audio> 标签的属性

属性描述
autoplayautoplay如果出现该属性,则音频在就绪后马上播放。
controlscontrols如果出现该属性,则向用户显示控件,比如播放按钮。
looploop如果出现该属性,则每当音频结束时重新开始播放。
preloadpreload

如果出现该属性,则音频在页面加载时进行加载,并预备播放。

如果使用 "autoplay",则忽略该属性。

srcurl要播放的音频的 URL。

 

 

或许有人问难道就没有一个好的支持IE8或者IE系列的播放音乐的标签吗?是有的,我测试过IE5也支持。在使用中的时候可以对各个浏览器进行判断即可。

<embed type="audio/mp3" src="${rootPath}/webpad/song.mp3" autostart="true" loop="false"></embed>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值