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

View file

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

View file

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