From ecb47b27e77a95e3eec5a5f136f46215554a2fe7 Mon Sep 17 00:00:00 2001 From: magnolia-fan Date: Fri, 24 Jun 2011 02:49:18 +0400 Subject: [PATCH] jPlayer integrated --- public/css/search.html | 13 ---- public/css/settings.html | 32 ---------- public/index.html | 18 ++---- public/js/beathaven/audio.js | 113 ---------------------------------- public/js/beathaven/player.js | 73 +++++++++++++--------- 5 files changed, 49 insertions(+), 200 deletions(-) delete mode 100644 public/css/search.html delete mode 100644 public/css/settings.html delete mode 100644 public/js/beathaven/audio.js diff --git a/public/css/search.html b/public/css/search.html deleted file mode 100644 index 93199b3..0000000 --- a/public/css/search.html +++ /dev/null @@ -1,13 +0,0 @@ -
-
- - -
- -
Artist info is loading for the first time now. Usually it takes less than a minute, please wait a bit.
-
-
-
Misspelled?
-
    -
    -
    \ No newline at end of file diff --git a/public/css/settings.html b/public/css/settings.html deleted file mode 100644 index dee94f3..0000000 --- a/public/css/settings.html +++ /dev/null @@ -1,32 +0,0 @@ -
    -
    -
    -
    Account
    -
    -
    Last.fm
    -
    -
    -
    - -
    -
    -
    -
    Username:
    -
    -
    -
    -
    -
    -
    -
    \ No newline at end of file diff --git a/public/index.html b/public/index.html index 7269b8b..40a1bd8 100644 --- a/public/index.html +++ b/public/index.html @@ -14,6 +14,7 @@ + @@ -21,16 +22,14 @@ - -
    -
    +
    Add some music to playlist
    @@ -48,9 +47,6 @@
      - - -
      @@ -64,17 +60,15 @@
    • Logout
    • - - -
      - - +
      Don't forget to log in, please. It's simple.
      -
      + +
      + diff --git a/public/js/beathaven/audio.js b/public/js/beathaven/audio.js deleted file mode 100644 index f55326f..0000000 --- a/public/js/beathaven/audio.js +++ /dev/null @@ -1,113 +0,0 @@ -var Audio = { - - audio: null, - - tid: null, - tinterval: 300, - ttime: 0, - - play: function() { - try { - this.audio.play(); - } catch(e) {} - }, - - pause: function() { - try { - this.audio.pause(); - } catch(e) {} - }, - - rewind: function() { - try { - this.audio.currentTime = 0; - } catch(e) {} - }, - - addTrack: function(id, url) { - if ($('#a'+ id).length == 0) { - $('#audiobox').html('') - } - }, - - setTrack: function(id) { - this.audio = document.getElementById('a'+ id); - $(this.audio).bind('play',function() { - $('#player .controls .play').hide(); - $('#player .controls .pause').show(); - }).bind('pause ended', function() { - $('#player .controls .pause').hide(); - $('#player .controls .play').show(); - }); - this.ttime = 0; - }, - - getLoadedPercent: function() { - try { - return Audio.audio.buffered.end(0) / Audio.audio.duration; - } catch(e) {} - return 0; - }, - - getPlayedPercent: function() { - try { - return Audio.audio.currentTime / Audio.audio.duration; - } catch(e) {} - return 0; - }, - - getListenedPercent: function() { - try { - if (Audio.audio.duration < 30 || Audio.ttime < 0) { - return -1; - } - return Audio.ttime / 1000 / Audio.audio.duration; - } catch(e) {} - return -1; - }, - - setPlayedPercent: function(val) { - if (typeof(this.audio.duration) != undefined) { - this.audio.currentTime = Math.round(val * this.audio.duration / 100); - return true; - } - return false; - }, - - skipToPercent: function(val) { - try { - this.audio.currentTime = this.audio.duration * val; - } catch(e) {} - }, - - startListener: function() { - Audio.killListener(); - Audio.tid = window.setTimeout(Audio.startListener, Audio.tinterval); - if (Audio.ttime !== -1) { - Audio.ttime += Audio.tinterval; - } - Player.updateUI( - Audio.getLoadedPercent(), - Audio.getPlayedPercent(), - Audio.getListenedPercent() - ); - var pp = Audio.getPlayedPercent(); - if (pp > 0.5) { - Audio.ttime = -1; - } - }, - - killListener: function() { - try { - window.clearTimeout(Audio.tid); - } catch(e) {} - } -} - -$('#player .controls .play').live('click', function(){ - Audio.play(); -}); - -$('#player .controls .pause').live('click', function(){ - Audio.pause(); -}); \ No newline at end of file diff --git a/public/js/beathaven/player.js b/public/js/beathaven/player.js index 42f5849..ad532cf 100644 --- a/public/js/beathaven/player.js +++ b/public/js/beathaven/player.js @@ -1,9 +1,43 @@ var Player = { bar_width: 330, + jp: null, + scrobbled: false, - getTrackUrl: function(data) { - + initJplayer: function() { + this.jp = $("#jplayer"); + this.jp.jPlayer({ + swfPath: "/js", + supplied: "mp3", + cssSelectorAncestor: "", + cssSelector: { + play: "#player .play", + pause: "#player .pause", + stop: "", + videoPlay: "", + seekBar: "", + playBar: "", + mute: "", + unmute: "", + volumeBar: "", + volumeBarValue: "", + currentTime: "", + duration: "" + } + }); + this.jp.bind($.jPlayer.event.timeupdate, function(e){ + data = e.jPlayer.status; + if (!Player.scrobbled && data.currentPercentAbsolute > 50) { + var tmp = $('#player .now-playing').text().split(' — '); + Player.scrobble(tmp[0], tmp[1]); + Player.scrobbled = true; + } + $('#player .progress .loaded').width(data.seekPercent * Player.bar_width / 100); + $('#player .progress .played').width(data.currentPercentAbsolute * Player.bar_width / 100); + }); + this.jp.bind($.jPlayer.event.ended, function(e){ + Player.setTrack(Player.nextTrack()); + }); }, addTrack: function(artist, track, length) { @@ -38,13 +72,8 @@ var Player = { }, playSource: function(url) { - var id = $('.playlist-tracks .now').attr('id').split('i')[1]; - Audio.pause(); - Audio.rewind(); - Audio.addTrack(id, url); - Audio.setTrack(id); - Audio.play(); - Audio.startListener(); + $('#jplayer').jPlayer('setMedia', {mp3: url}).jPlayer('play'); + Player.scrobbled = false; }, nextTrack: function() { @@ -67,26 +96,6 @@ var Player = { } }, - updateUI: function(buffered, played, listened) { - $('#player .loaded').width(Math.round(buffered * this.bar_width)); - $('#player .played').width(Math.round(played * this.bar_width)); - if (played == 1) { - Audio.killListener(); - Player.setTrack(Player.nextTrack()); - } - if (played > 0.5 && listened > 0) { - var tmp = $('#player .now-playing').text().split(' — '); - Player.scrobble(tmp[0], tmp[1]); - } - }, - - reset: function() { - Audio.pause(); - Audio.killListener(); - $('#player .loaded, #player .played').width(0); - $('#player .now-playing').text('Select track'); - }, - updateNowListening: function(artist, track) { Session.query('/lastfm/listening?r='+ Math.random(), {'artist': artist, 'track': track}) }, @@ -96,6 +105,10 @@ var Player = { } } +$(function(){ + Player.initJplayer(); +}); + $('#player .controls .prev').live('click', function(){ Player.setTrack(Player.prevTrack()); }); @@ -150,5 +163,5 @@ $('.playlist-tracks li').live('dblclick', function(){ }); $('#player .progress').live('click', function(e){ - Audio.skipToPercent(e.offsetX / Player.bar_width); + $('#jplayer').jPlayer('playHead', Math.round((e.offsetX / Player.bar_width) * 100)); }); \ No newline at end of file