Bringing more consistency in music.mpd.js regardless of the backend

This commit is contained in:
Fabio Manganiello 2019-02-13 00:50:58 +01:00
parent 0697598a86
commit 8a9c868f77
3 changed files with 22 additions and 7 deletions

View file

@ -4,8 +4,8 @@ $(document).ready(function() {
curPath = [],
curTrackUpdateHandler,
curTrackElapsed = {
timestamp: null,
elapsed: null,
timestamp: undefined,
elapsed: undefined,
},
$musicSearchForm = $('#music-search-form'),
@ -125,6 +125,10 @@ $(document).ready(function() {
$('#seek-time-length').text(length ? timeToStr(length) : '-:--');
seekInterval = setInterval(function() {
if (curTrackElapsed.elapsed === undefined) {
return;
}
var length = parseInt($trackSeeker.attr('max'));
var value = parseInt((new Date().getTime() - curTrackElapsed.timestamp)/1000)
+ curTrackElapsed.elapsed;
@ -169,7 +173,7 @@ $(document).ready(function() {
var updatePlayingTrack = function(track) {
return function() {
var $curTrack = $playlistContent.find('.playlist-track').filter(
function() { return $(this).data('pos') == track.pos });
function() { return $(this).data('file') === track.file });
if ($curTrack.length === 0) {
return;

View file

@ -105,20 +105,26 @@ $(document).ready(function() {
};
var refreshStatus = function(status) {
if (!status) {
return;
}
if ('state' in status) {
setState(state=status.state);
}
if ('elapsed' in status) {
setTrackElapsed(status.elapsed);
}
if ('position' in status) {
} else if ('position' in status) {
setTrackElapsed(status.position);
}
};
var refreshTrack = function(track) {
if (!track) {
return;
}
if ('time' in track) {
setTrackTime(track.time);
}

View file

@ -143,6 +143,10 @@ class MusicMopidyBackend(Backend):
track = self._parse_track(track)
if not track:
return
status['state'] = 'play'
status['position'] = 0.0
status['time'] = track.get('time')
self.bus.post(NewPlayingTrackEvent(status=status, track=track))
elif event == 'stream_title_changed':
m = re.match('^\s*(.+?)\s+-\s+(.*)\s*$', msg.get('title', ''))
@ -151,7 +155,8 @@ class MusicMopidyBackend(Backend):
track['artist'] = m.group(1)
track['title'] = m.group(2)
track['position'] = 0.0
status['state'] = 'play'
status['position'] = 0.0
self.bus.post(NewPlayingTrackEvent(status=status, track=track))
elif event == 'volume_changed':
status['volume'] = msg.get('volume')