diff --git a/app/Controller/SongsController.php b/app/Controller/SongsController.php index 0b95f3b..cf4645f 100644 --- a/app/Controller/SongsController.php +++ b/app/Controller/SongsController.php @@ -594,6 +594,7 @@ public function download($id = null) { } $this->response->file($song['Song']['path'], array('download' => true)); + $this->response->cache('-1 minute', '+2 hours'); return $this->response; } diff --git a/app/webroot/js/Player.js b/app/webroot/js/Player.js index 8546c5e..5acaa15 100644 --- a/app/webroot/js/Player.js +++ b/app/webroot/js/Player.js @@ -1,6 +1,8 @@ function Player() { var audioElement = document.createElement('audio'); + var bufferAudioElement = document.createElement('audio'); + var buffered = false; var playlist = new Playlist(); var self = this; var selected = null; @@ -21,6 +23,20 @@ function Player() { this.addEventListener = function(event, callback) { audioElement.addEventListener(event, callback, true); }; + this.addEventListener('progress', function() { + setTimeout(function() { + if(self.getBuffered() == self.getDuration() && self.hasNext() && !buffered) { + var index = playlist.getCurrentIndex()+1; + if (index == playlist.size()) { + index = 0; + } + bufferAudioElement.src = playlist.getByIndex(index).url; + bufferAudioElement.play(); + bufferAudioElement.pause(); + buffered = true; + } + }, 500); + }); this.getPlaylist = function() { return playlist.getSongs(); }; @@ -45,6 +61,10 @@ function Player() { this.seek = function(currentTime) { if(currentTime <= audioElement.duration){ audioElement.currentTime = currentTime; + if (this.isPlaying()) { + audioElement.pause(); + audioElement.play(); + } } }; this.canPlay = function() { @@ -63,6 +83,7 @@ function Player() { }else if(audioElement.src == "" && selected != null) { audioElement.src = selected.url; } + buffered = false; if(audioElement.src != "") { audioElement.play(); } diff --git a/app/webroot/js/player-nav.js b/app/webroot/js/player-nav.js index f68f275..9e58077 100644 --- a/app/webroot/js/player-nav.js +++ b/app/webroot/js/player-nav.js @@ -368,7 +368,9 @@ function init() { }); player.addEventListener('progress', function() { - $timeBar.slider('buffered', player.getBuffered()); + setTimeout(function() { + $timeBar.slider('buffered', player.getBuffered()); + }, 500); }); player.addEventListener('volumechange', function() {