Skip to content
This repository has been archived by the owner on Jun 7, 2019. It is now read-only.

Commit

Permalink
Add the ability to show the track time in the panel.
Browse files Browse the repository at this point in the history
New format values are trackDuration and trackPosition

closes #430
  • Loading branch information
JasonLG1979 committed Nov 1, 2017
1 parent 10cbcc7 commit 98754b7
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion src/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ var PlayerState = new Lang.Class({
trackListMetaData: null,

trackTime: null,
trackDuration: null,
trackPosition: null,
trackTitle: null,
trackAlbum: null,
trackArtist: null,
Expand Down Expand Up @@ -496,6 +498,7 @@ var MPRISPlayer = new Lang.Class({

if (props.Metadata) {
this.parseMetadata(props.Metadata.deep_unpack(), newState);
newState.trackDuration = this._formatTime(newState.trackLength)
newState.emitSignal = true;
if (newState.trackUrl !== this.state.trackUrl || newState.trackObj !== this.state.trackObj) {
this._refreshProperties(newState);
Expand Down Expand Up @@ -639,8 +642,11 @@ var MPRISPlayer = new Lang.Class({
if (this._trackTime >= trackLength) {
value = 0;
}
let newState = new PlayerState();
this._trackTime = value;
this.emit('update-player-state', new PlayerState({trackTime: this._trackTime}));
newState.trackTime = value;
newState.trackPosition = this._formatTime(value);
this.emit('update-player-state', newState);
},

get trackTime() {
Expand Down Expand Up @@ -1075,6 +1081,19 @@ var MPRISPlayer = new Lang.Class({
}
},

_formatTime: function(s) {
if (Number.isNaN(s) || s < 0) {
return '0:00'
}
let h = Math.floor(s / 3600);
let m = Math.floor((s % 3600) / 60);
s = s % 60;
s = s < 10 ? '0' + s : s;
m = m < 10 && h > 0 ? '0' + m + ':' : m + ':';
h = h > 0 ? h + ':' : '';
return h + m + s;
},

destroy: function() {
// Cancel all pending timeouts.
this._stopTimer();
Expand Down

0 comments on commit 98754b7

Please sign in to comment.