getCurrentSongTime() is not working/duration is not available
I’m using MPD 0.19
Moreover, the duration is not sent so getCurrentSongTime() return, NaN. That’s why I needed to request update to get the ‘elapsed’ that is returned by MPD. It seems that the status is not updating by itself. I made a fork that allow the client to request an update.
I don’t really understand how one is supposed to get the music length if the duration is not sent … but I’m using Auremo on the same MPD and it seems to work.
I will make a PR as soon as I fixed this problem but if you can help me to understand how I should proceed it would help!
Thanks for this project :)
In version 0.20 the duration is sent as part of the status, but I think I get duration for the current song from the 'time' field returned as a result of the playlistinfo command. I know duration for the current song from the status command was added in 0.20, so that might be related to what's going on. Maybe the time field for songs was added in 0.20 also and the documentation just glossed over that.
You might want put a breakpoint in the QueueSong constructor (line 2167) and see if the given 'source' object has a 'time' field. If it doesn't you might want to see if there is a 'duration' field. I think I switched to using time because duration wasn't always reliable, but I might be misremembering that, it might just be because time is an integer and MPD uses ints everywhere else. Maybe we should be using source.duration field for MPD.Song.getDuration (line 2054).
If the duration was unavailable I would expect getCurrentSongTime to work until near the end of a song (last fraction of a second) though. Is that the behaviour you are seeing? or is it just completely broken all the time?
I have investigate and by reading mpc source code I saw that the "time" field is not exactly " time: total time elapsed (of current playing/paused song) " as mentionned in the doc (http://www.musicpd.org/doc/protocol/command_reference.html) It is "time_elapsed:_total_time
So I made this change : https://github.com/graindcafe/MPD.js/commit/fb335a128e7d506fc57488028572af0cd7b62df5
I'm not reading regular file on hard drive but HTTP stream and MPD.Song.getDuration is always empty. mpc is unable to give me the duration when I use mpc current -f %time% but it shows it with mpc status
I lost track of this issue, sorry for the... two year delay. I looked over your changes and I noticed you also improved some error handling, I'll pull these changes in if you want to make a pull request.