标题:怎么可以点击audio播放相应的音频列表, 而互不影响呢
只看楼主
weiwei85530
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2016-4-11
 问题点数:0 回复次数:0 
怎么可以点击audio播放相应的音频列表, 而互不影响呢
html代码
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.
<html xmlns="http://www.
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>支持iOS安卓html5播放器代码</title>
<!--必要样式-->
<link rel="stylesheet" type="text/css" href="styles.css" media="all" >

</head>
<body>


<div id="myAudio">
<audio>
<source title="正房" src="1.mp3" />
<source title="厨房" src="2.mp3" />
</audio>
    <div class="play_controls">
<a class="btn_previous" style="display:none;">e</a>
<a class="btn_play">c</a>
<a class="btn_next" style="display:none;">d</a>
</div>
</div>
<div id="myAudio">
<audio>
<source title="正房" src="1.mp3" />
<source title="厨房" src="2.mp3" />
</audio>
    <div class="play_controls">
<a class="btn_previous" style="display:none;">e</a>
<a class="btn_play">c</a>
<a class="btn_next" style="display:none;">d</a>
</div>
</div>

<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript" src="js/AudioPlayer.js"></script>
<script type="text/javascript">
$(function(){
$("#myAudio").initAudio();
});
</script>
</body>
</html>

js代码
(function($){
jQuery.fn.extend({
"initAudio" : function(){
var myAudio = $("audio",this)[0];
var $sourceList = $("source",this);
var currentSrcIndex = 0;
var currentSr = "";

/*播放、暂停、上一首、下一首功能实现*/
$(".btn_play").click(function(){
if (myAudio.paused) {
myAudio.play();
} else {
myAudio.pause();
}
});
$(".btn_next").click(function(){
++currentSrcIndex > $sourceList.length - 1 && (currentSrcIndex = 0);
currentSrc = $("#myAudio source").eq(currentSrcIndex).prop("src");
myAudio.src = currentSrc;
myAudio.play();
});
$(".btn_previous").click(function(){
--currentSrcIndex < 0 && (currentSrcIndex = 0);
currentSrc = $("#myAudio source").eq(currentSrcIndex).prop("src");
myAudio.src = currentSrc;
myAudio.play();
});

/*audio元素事件绑定*/
$(myAudio).bind("play",function(){
$(".btn_play").text("h");
});
$(myAudio).bind("pause",function(){
$(".btn_play").text("c");
});
$(myAudio).bind("ended",function(){
$(".btn_next").triggerHandler("click");
});
}
});
})(jQuery)


css代码
/*使用font-face来制作播放按钮的图标*/
#myAudio .play_controls a {
    font-family: "icomoon";
    cursor: pointer;
    font-size:12px;
    color:#CCC;
}
@font-face {
    font-family: 'icomoon';
    src:url('fonts/icomoon.eot');
    src:url('fonts/icomoon.eot?#iefix') format('embedded-opentype'),
        url('fonts/icomoon.woff') format('woff'),
        url('fonts/icomoon.ttf') format('truetype'),
        url('fonts/icomoon.svg#icomoon') format('svg');
}
搜索更多相关主题的帖子: media source PUBLIC 播放器 content 
2016-04-11 14:13



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-463513-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.080176 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved