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

Commit 98754b7

Browse files
committed
Add the ability to show the track time in the panel.
New format values are trackDuration and trackPosition closes #430
1 parent 10cbcc7 commit 98754b7

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

src/player.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ var PlayerState = new Lang.Class({
6161
trackListMetaData: null,
6262

6363
trackTime: null,
64+
trackDuration: null,
65+
trackPosition: null,
6466
trackTitle: null,
6567
trackAlbum: null,
6668
trackArtist: null,
@@ -496,6 +498,7 @@ var MPRISPlayer = new Lang.Class({
496498

497499
if (props.Metadata) {
498500
this.parseMetadata(props.Metadata.deep_unpack(), newState);
501+
newState.trackDuration = this._formatTime(newState.trackLength)
499502
newState.emitSignal = true;
500503
if (newState.trackUrl !== this.state.trackUrl || newState.trackObj !== this.state.trackObj) {
501504
this._refreshProperties(newState);
@@ -639,8 +642,11 @@ var MPRISPlayer = new Lang.Class({
639642
if (this._trackTime >= trackLength) {
640643
value = 0;
641644
}
645+
let newState = new PlayerState();
642646
this._trackTime = value;
643-
this.emit('update-player-state', new PlayerState({trackTime: this._trackTime}));
647+
newState.trackTime = value;
648+
newState.trackPosition = this._formatTime(value);
649+
this.emit('update-player-state', newState);
644650
},
645651

646652
get trackTime() {
@@ -1075,6 +1081,19 @@ var MPRISPlayer = new Lang.Class({
10751081
}
10761082
},
10771083

1084+
_formatTime: function(s) {
1085+
if (Number.isNaN(s) || s < 0) {
1086+
return '0:00'
1087+
}
1088+
let h = Math.floor(s / 3600);
1089+
let m = Math.floor((s % 3600) / 60);
1090+
s = s % 60;
1091+
s = s < 10 ? '0' + s : s;
1092+
m = m < 10 && h > 0 ? '0' + m + ':' : m + ':';
1093+
h = h > 0 ? h + ':' : '';
1094+
return h + m + s;
1095+
},
1096+
10781097
destroy: function() {
10791098
// Cancel all pending timeouts.
10801099
this._stopTimer();

0 commit comments

Comments
 (0)