Skip to content

Commit

Permalink
Integrate progress bar
Browse files Browse the repository at this point in the history
Issue: tiliado/nuvolaplayer#155

Signed-off-by: Jiří Janoušek <[email protected]>
  • Loading branch information
jiri-janousek committed Jun 11, 2017
1 parent 4ea8024 commit fd66209
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions integrate.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ WebApp.update = function()
track.artist = elm ? elm.innerText || null : null;
elm = document.querySelector(".player .player-cover img");
track.artLocation = elm ? elm.src || null : null;
track.length = this._getTrackLength();
elm = document.querySelector(".player .player-progress .progress-time");
var elapsed = elm ? elm.innerText || null : null;

/*
* No idea where #document comes from.
Expand All @@ -91,10 +94,23 @@ WebApp.update = function()
player.setCanGoPrev(this._isButtonEnabled("prev"));
player.setCanGoNext(this._isButtonEnabled("next"));

if (Nuvola.checkVersion && Nuvola.checkVersion(4, 4, 17))
{
if (state !== PlaybackState.UNKNOWN)
player.setTrackPosition(elapsed);
player.setCanSeek(state !== PlaybackState.UNKNOWN);
}

// Schedule the next update
setTimeout(this.update.bind(this), 500);
}

WebApp._getTrackLength = function()
{
var elm = document.querySelector(".player .player-progress .progress-length");
return Nuvola.parseTimeUsec(elm ? elm.innerText || null : null);
}

WebApp._isButtonEnabled = function(name)
{
var button = this._getButton(name);
Expand Down Expand Up @@ -144,6 +160,12 @@ WebApp._onActionActivated = function(emitter, name, param)
case PlayerAction.NEXT_SONG:
this._clickButton("next");
break;
case PlayerAction.SEEK:
var bar = document.querySelector(".player .player-progress .progress-buffer");
var total = this._getTrackLength();
if (bar && total >= param)
Nuvola.clickOnElement(bar, param / total, 0.5);
break;
}
}

Expand Down

0 comments on commit fd66209

Please sign in to comment.