get total time from mpd status, not from currently playing track
it seems that even if track info doesn't provide total track length, mpd status does, which allows for seeking and displaying progressbar.
This commit is contained in:
@@ -129,6 +129,7 @@ namespace MPD
|
||||
long long GetPlaylistID() const { return isConnected && itsCurrentStatus ? itsCurrentStatus->playlist : -1; }
|
||||
long long GetOldPlaylistID() const { return isConnected && itsOldStatus ? itsOldStatus->playlist : -1; }
|
||||
int GetElapsedTime() const { return isConnected && itsCurrentStatus ? itsCurrentStatus->elapsedTime : -1; }
|
||||
int GetTotalTime() const { return isConnected && itsCurrentStatus ? itsCurrentStatus->totalTime : 0; }
|
||||
unsigned GetBitrate() const { return isConnected && itsCurrentStatus ? itsCurrentStatus->bitRate : 0; }
|
||||
|
||||
size_t GetMaxPlaylistLength() const { return itsMaxPlaylistLength; }
|
||||
|
||||
@@ -386,10 +386,9 @@ int main(int argc, char *argv[])
|
||||
&& mouse_event.y == LINES-(Config.statusbar_visibility ? 2 : 1)
|
||||
) // progressbar
|
||||
{
|
||||
const Song *s = myPlaylist->NowPlayingSong();
|
||||
if (!s)
|
||||
if (!myPlaylist->isPlaying())
|
||||
continue;
|
||||
Mpd.Seek(s->GetTotalLength()*mouse_event.x/double(COLS));
|
||||
Mpd.Seek(Mpd.GetTotalTime()*mouse_event.x/double(COLS));
|
||||
UpdateStatusImmediately = 1;
|
||||
}
|
||||
else if (mouse_event.bstate & BUTTON1_PRESSED
|
||||
@@ -1091,16 +1090,16 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
else if (Keypressed(input, Key.SeekForward) || Keypressed(input, Key.SeekBackward))
|
||||
{
|
||||
const Song *s = myPlaylist->NowPlayingSong();
|
||||
|
||||
if (!s)
|
||||
continue;
|
||||
|
||||
if (!s->GetTotalLength())
|
||||
if (!Mpd.GetTotalTime())
|
||||
{
|
||||
ShowMessage("Unknown item length!");
|
||||
continue;
|
||||
}
|
||||
|
||||
const Song *s = myPlaylist->NowPlayingSong();
|
||||
if (!s)
|
||||
continue;
|
||||
|
||||
LockProgressbar();
|
||||
LockStatusbar();
|
||||
|
||||
@@ -1118,13 +1117,13 @@ int main(int argc, char *argv[])
|
||||
|
||||
int howmuch = Config.incremental_seeking ? (myPlaylist->Timer()-t)/2+Config.seek_time : Config.seek_time;
|
||||
|
||||
if (songpos < s->GetTotalLength() && Keypressed(input, Key.SeekForward))
|
||||
if (Keypressed(input, Key.SeekForward) && songpos < Mpd.GetTotalTime())
|
||||
{
|
||||
songpos += howmuch;
|
||||
if (songpos > s->GetTotalLength())
|
||||
songpos = s->GetTotalLength();
|
||||
if (songpos > Mpd.GetTotalTime())
|
||||
songpos = Mpd.GetTotalTime();
|
||||
}
|
||||
if (songpos < s->GetTotalLength() && songpos > 0 && Keypressed(input, Key.SeekBackward))
|
||||
else if (Keypressed(input, Key.SeekBackward) && songpos > 0)
|
||||
{
|
||||
songpos -= howmuch;
|
||||
if (songpos < 0)
|
||||
@@ -1138,12 +1137,12 @@ int main(int argc, char *argv[])
|
||||
if (Config.display_remaining_time)
|
||||
{
|
||||
tracklength = "-";
|
||||
tracklength += Song::ShowTime(s->GetTotalLength()-songpos);
|
||||
tracklength += Song::ShowTime(Mpd.GetTotalTime()-songpos);
|
||||
}
|
||||
else
|
||||
tracklength = Song::ShowTime(songpos);
|
||||
tracklength += "/";
|
||||
tracklength += s->GetLength();
|
||||
tracklength += MPD::Song::ShowTime(Mpd.GetTotalTime());
|
||||
*wHeader << XY(0, 0) << tracklength << " ";
|
||||
wHeader->Refresh();
|
||||
}
|
||||
@@ -1153,16 +1152,16 @@ int main(int argc, char *argv[])
|
||||
if (Config.display_remaining_time)
|
||||
{
|
||||
tracklength += "-";
|
||||
tracklength += Song::ShowTime(s->GetTotalLength()-songpos);
|
||||
tracklength += Song::ShowTime(Mpd.GetTotalTime()-songpos);
|
||||
}
|
||||
else
|
||||
tracklength = Song::ShowTime(songpos);
|
||||
tracklength += "/";
|
||||
tracklength += s->GetLength();
|
||||
tracklength += MPD::Song::ShowTime(Mpd.GetTotalTime());
|
||||
tracklength += "]";
|
||||
*wFooter << XY(wFooter->GetWidth()-tracklength.length(), 1) << tracklength;
|
||||
}
|
||||
double progressbar_size = songpos/double(s->GetTotalLength());
|
||||
double progressbar_size = songpos/double(Mpd.GetTotalTime());
|
||||
unsigned howlong = wFooter->GetWidth()*progressbar_size;
|
||||
|
||||
mvwhline(wFooter->Raw(), 0, 0, 0, wFooter->GetWidth());
|
||||
@@ -1488,16 +1487,16 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
else if (Keypressed(input, Key.GoToPosition))
|
||||
{
|
||||
const Song *s = myPlaylist->NowPlayingSong();
|
||||
|
||||
if (!s)
|
||||
continue;
|
||||
|
||||
if (!s->GetTotalLength())
|
||||
if (!Mpd.GetTotalTime())
|
||||
{
|
||||
ShowMessage("Unknown item length!");
|
||||
continue;
|
||||
}
|
||||
|
||||
const Song *s = myPlaylist->NowPlayingSong();
|
||||
if (!s)
|
||||
continue;
|
||||
|
||||
LockStatusbar();
|
||||
Statusbar() << "Position to go (in %/mm:ss/seconds(s)): ";
|
||||
std::string position = wFooter->GetString();
|
||||
@@ -1514,7 +1513,7 @@ int main(int argc, char *argv[])
|
||||
newpos = StrToInt(position)*60 + StrToInt(position.substr(position.find(':')+1));
|
||||
}
|
||||
catch (std::out_of_range) { }
|
||||
if (newpos >= 0 && newpos <= s->GetTotalLength())
|
||||
if (newpos >= 0 && newpos <= Mpd.GetTotalTime())
|
||||
Mpd.Seek(newpos);
|
||||
else
|
||||
ShowMessage("Out of bounds, 0:00-%s possible for mm:ss, %s given.", s->GetLength().c_str(), MPD::Song::ShowTime(newpos).c_str());
|
||||
@@ -1522,7 +1521,7 @@ int main(int argc, char *argv[])
|
||||
else if (position.find('s') != std::string::npos) // probably position in seconds
|
||||
{
|
||||
newpos = StrToInt(position);
|
||||
if (newpos >= 0 && newpos <= s->GetTotalLength())
|
||||
if (newpos >= 0 && newpos <= Mpd.GetTotalTime())
|
||||
Mpd.Seek(newpos);
|
||||
else
|
||||
ShowMessage("Out of bounds, 0-%d possible for seconds, %d given.", s->GetTotalLength(), newpos);
|
||||
@@ -1531,7 +1530,7 @@ int main(int argc, char *argv[])
|
||||
{
|
||||
newpos = StrToInt(position);
|
||||
if (newpos >= 0 && newpos <= 100)
|
||||
Mpd.Seek(s->GetTotalLength()*newpos/100.0);
|
||||
Mpd.Seek(Mpd.GetTotalTime()*newpos/100.0);
|
||||
else
|
||||
ShowMessage("Out of bounds, 0-100 possible for %%, %d given.", newpos);
|
||||
}
|
||||
|
||||
@@ -415,14 +415,14 @@ void NcmpcppStatusChanged(Connection *, StatusChanges changed, void *)
|
||||
if (Config.display_remaining_time)
|
||||
{
|
||||
tracklength = "-";
|
||||
tracklength += Song::ShowTime(np.GetTotalLength()-elapsed);
|
||||
tracklength += Song::ShowTime(Mpd.GetTotalTime()-elapsed);
|
||||
}
|
||||
else
|
||||
tracklength = Song::ShowTime(elapsed);
|
||||
if (np.GetTotalLength())
|
||||
if (Mpd.GetTotalTime())
|
||||
{
|
||||
tracklength += "/";
|
||||
tracklength += np.GetLength();
|
||||
tracklength += MPD::Song::ShowTime(Mpd.GetTotalTime());
|
||||
}
|
||||
// bitrate here doesn't look good, but it can be moved somewhere else later
|
||||
if (Config.display_bitrate && Mpd.GetBitrate())
|
||||
@@ -466,17 +466,17 @@ void NcmpcppStatusChanged(Connection *, StatusChanges changed, void *)
|
||||
tracklength += " kbps]";
|
||||
}
|
||||
tracklength += " [";
|
||||
if (np.GetTotalLength())
|
||||
if (Mpd.GetTotalTime())
|
||||
{
|
||||
if (Config.display_remaining_time)
|
||||
{
|
||||
tracklength += "-";
|
||||
tracklength += Song::ShowTime(np.GetTotalLength()-elapsed);
|
||||
tracklength += Song::ShowTime(Mpd.GetTotalTime()-elapsed);
|
||||
}
|
||||
else
|
||||
tracklength += Song::ShowTime(elapsed);
|
||||
tracklength += "/";
|
||||
tracklength += np.GetLength();
|
||||
tracklength += MPD::Song::ShowTime(Mpd.GetTotalTime());
|
||||
tracklength += "]";
|
||||
}
|
||||
else
|
||||
@@ -492,11 +492,11 @@ void NcmpcppStatusChanged(Connection *, StatusChanges changed, void *)
|
||||
}
|
||||
if (!block_progressbar_update)
|
||||
{
|
||||
double progressbar_size = elapsed/double(np.GetTotalLength());
|
||||
double progressbar_size = elapsed/double(Mpd.GetTotalTime());
|
||||
unsigned howlong = wFooter->GetWidth()*progressbar_size;
|
||||
*wFooter << Config.progressbar_color;
|
||||
mvwhline(wFooter->Raw(), 0, 0, 0, wFooter->GetWidth());
|
||||
if (np.GetTotalLength())
|
||||
if (Mpd.GetTotalTime())
|
||||
{
|
||||
for (unsigned i = 0; i < howlong; ++i)
|
||||
*wFooter << Config.progressbar[0];
|
||||
|
||||
Reference in New Issue
Block a user