Added buffering
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
var audio;
|
||||
var prev_audio;
|
||||
var next_audio;
|
||||
var utid;
|
||||
$(function(){
|
||||
$.extend($.fn.disableTextSelect = function() {
|
||||
@@ -69,6 +71,11 @@ function updatePlayer() {
|
||||
progress = Math.round((cur_time / duration) * 390);
|
||||
$('#player .progress-loaded').css('width', loaded +'px')
|
||||
$('#player .progress-point').css('margin-left', progress +'px')
|
||||
|
||||
/* Starting buffering next track */
|
||||
if (Math.round(cur_time / duration * 100) > 70) {
|
||||
addAudio(next_audio);
|
||||
}
|
||||
}
|
||||
utid = window.setTimeout(updatePlayer, 100);
|
||||
}
|
||||
@@ -79,7 +86,7 @@ function formatTime(sec) {
|
||||
return m +':'+ (s < 10 ? '0' : '') +s;
|
||||
}
|
||||
function playTrack(artist, track, id) {
|
||||
$(audio).attr('src', '/listen/'+ id +'.mp3');
|
||||
switchAudio(id);
|
||||
$('#player .track-title').html(artist +' — '+ track);
|
||||
$('#player .time-played').html('0:00');
|
||||
$('#player .time-left').html('0:00');
|
||||
@@ -130,3 +137,14 @@ function addToPlaylist(artist, track, length, id) {
|
||||
}
|
||||
$('#player .playlist .count').html($('#playlist ul.list li').length);
|
||||
}
|
||||
function addAudio(id) {
|
||||
if ($('#audio_'+ id).length == 0) {
|
||||
$('#audiobox').append('<audio id="audio_'+ id +'" src="/listen/'+ id +'.mp3" preload="preload"></audio>');
|
||||
}
|
||||
}
|
||||
function switchAudio(id) {
|
||||
if ($('#audio_'+ id).length == 0) {
|
||||
addAudio(id);
|
||||
}
|
||||
audio = document.getElementById('audio_'+ id);
|
||||
}
|
||||
@@ -1,3 +1,10 @@
|
||||
audio {
|
||||
width: 0;
|
||||
height: 0;
|
||||
position: absolute;
|
||||
top: -1000px;
|
||||
left: -1000px;
|
||||
}
|
||||
#player {
|
||||
position: fixed;
|
||||
width: 750px;
|
||||
|
||||
Reference in New Issue
Block a user