@@ -61,6 +61,8 @@ var PlayerState = new Lang.Class({
61
61
trackListMetaData : null ,
62
62
63
63
trackTime : null ,
64
+ trackDuration : null ,
65
+ trackPosition : null ,
64
66
trackTitle : null ,
65
67
trackAlbum : null ,
66
68
trackArtist : null ,
@@ -496,6 +498,7 @@ var MPRISPlayer = new Lang.Class({
496
498
497
499
if ( props . Metadata ) {
498
500
this . parseMetadata ( props . Metadata . deep_unpack ( ) , newState ) ;
501
+ newState . trackDuration = this . _formatTime ( newState . trackLength )
499
502
newState . emitSignal = true ;
500
503
if ( newState . trackUrl !== this . state . trackUrl || newState . trackObj !== this . state . trackObj ) {
501
504
this . _refreshProperties ( newState ) ;
@@ -639,8 +642,11 @@ var MPRISPlayer = new Lang.Class({
639
642
if ( this . _trackTime >= trackLength ) {
640
643
value = 0 ;
641
644
}
645
+ let newState = new PlayerState ( ) ;
642
646
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 ) ;
644
650
} ,
645
651
646
652
get trackTime ( ) {
@@ -1075,6 +1081,19 @@ var MPRISPlayer = new Lang.Class({
1075
1081
}
1076
1082
} ,
1077
1083
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
+
1078
1097
destroy : function ( ) {
1079
1098
// Cancel all pending timeouts.
1080
1099
this . _stopTimer ( ) ;
0 commit comments