151 lines
3.8 KiB
JavaScript
151 lines
3.8 KiB
JavaScript
var player;
|
|
var id = $('#msgfmplayer-ctl input[name=trackid]').val();
|
|
var track = $('#msgfmplayer-ctl input[name=track]').val();
|
|
|
|
var mp3player = {
|
|
loaded : function(){
|
|
player = document.getElementById('jquery_jplayer');
|
|
|
|
$(".jp-play").click(function(e) {
|
|
player.play();
|
|
});
|
|
$('.jp-pause').click(function(e){
|
|
player.pause();
|
|
});
|
|
$('.jp-stop').click(function(e){
|
|
player.pause();
|
|
player.currentTime = 0;
|
|
});
|
|
$('.jp-mute').click(function(e){
|
|
player.volume = 0;
|
|
$( "#volume-ctl" ).slider("value",0);
|
|
});
|
|
$('.jp-volume-max').click(function(e){
|
|
player.volume = 1;
|
|
$( "#volume-ctl" ).slider("value",100);
|
|
});
|
|
|
|
$( "#volume-ctl" ).slider({
|
|
range: "min",
|
|
min: 0,
|
|
max: 100,
|
|
step: 10,
|
|
value: 60,
|
|
slide: function( event, ui ) {
|
|
player.volume = ui.value / 100;
|
|
}
|
|
});
|
|
|
|
player.onplay = function(e){
|
|
$('.jp-play').hide();
|
|
$('.jp-pause').show();
|
|
$('#volume-ctl').show();
|
|
$('#play-status').show();
|
|
};
|
|
|
|
player.onpause = function(e){
|
|
$('.jp-play').show();
|
|
$('.jp-pause').hide();
|
|
$('#volume-ctl').hide();
|
|
$('#play-status').hide();
|
|
};
|
|
|
|
player.onended = function(e){
|
|
mp3player.playcount(id);
|
|
$('#play-status').hide();
|
|
};
|
|
|
|
player.onvolumechange = function(e){
|
|
if(player.volume == 0)
|
|
{
|
|
$('.jp-volume-max').show();
|
|
$('.jp-mute').hide();
|
|
}else{
|
|
$('.jp-volume-max').hide();
|
|
$('.jp-mute').show();
|
|
}
|
|
};
|
|
|
|
player.ontimeupdate = function(e){
|
|
$("#progressbar").slider("value",Math.round((player.currentTime / player.duration) * 100));
|
|
$('#timer_current').html(formatSeconds(player.currentTime));
|
|
};
|
|
|
|
player.ondurationchange = function(e){
|
|
$('#timer_duration').html(formatSeconds(player.duration));
|
|
};
|
|
},
|
|
|
|
playcount : function(id){
|
|
$.ajax({
|
|
type:"POST",
|
|
url:"/voice/count/" + id,
|
|
data:"",
|
|
success:function(data){$("#play_count").html( parseInt($('#play_count').html()) + 1 )},
|
|
timeout: 5000,
|
|
error: function(){},
|
|
beforeSend: function(){},
|
|
complete: function(){}
|
|
});
|
|
},
|
|
|
|
appendplayer : function(){
|
|
$('#html5player').html('<audio controls="controls" id="jquery_jplayer" style="display:none">'
|
|
+' <source src="'+track+'" type="audio/mpeg">'
|
|
+' 您使用的浏览器可能不支持音频播放'
|
|
+'</audio>');
|
|
},
|
|
|
|
appendtimer : function(){
|
|
$('#html5player').after('<div class="pull-right" id="playtimer"><span id="timer_current"></span>/<span id="timer_duration"></span></div>');
|
|
},
|
|
|
|
changeplayer : function(){
|
|
$('#play-status').html('<div class="panel-body"><div id="progressbar"></div></div>');
|
|
$( "#progressbar" ).slider({
|
|
range: "min",
|
|
min: 0,
|
|
max: 100,
|
|
step: 1,
|
|
value: 0,
|
|
slide: function( event, ui ) {
|
|
player.currentTime = Math.round((ui.value / 100) * player.duration);
|
|
}
|
|
});
|
|
}
|
|
|
|
}; //mp3player
|
|
|
|
$(document).ready(function(e) {
|
|
mp3player.appendplayer();
|
|
mp3player.appendtimer();
|
|
mp3player.changeplayer();
|
|
mp3player.loaded();
|
|
player.play();
|
|
});
|
|
|
|
function formatSeconds(value) {
|
|
var theTime = Number(value);
|
|
var theTime1 = 0;
|
|
var theTime2 = 0;
|
|
//alert(theTime);
|
|
if(theTime > 60) {
|
|
theTime1 = Number(theTime/60);
|
|
theTime = Number(theTime%60);
|
|
//alert(theTime1+"-"+theTime);
|
|
if(theTime1 > 60) {
|
|
theTime2 = Number(theTime1/60);
|
|
theTime1 = Number(theTime%60);
|
|
}
|
|
}
|
|
var result = ""+Math.round(theTime)+"";
|
|
if(theTime1 > 0) {
|
|
result = ""+parseInt(theTime1)+":"+result;
|
|
}else{
|
|
result = ""+0+":"+result;
|
|
}
|
|
if(theTime2 > 0) {
|
|
result = ""+parseInt(theTime2)+":"+result;
|
|
}
|
|
return result;
|
|
}
|