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:
Andrzej Rybczak
2009-09-09 18:32:57 +02:00
parent 6cc4eac00e
commit 30b8622776
3 changed files with 35 additions and 35 deletions

View File

@@ -129,6 +129,7 @@ namespace MPD
long long GetPlaylistID() const { return isConnected && itsCurrentStatus ? itsCurrentStatus->playlist : -1; } long long GetPlaylistID() const { return isConnected && itsCurrentStatus ? itsCurrentStatus->playlist : -1; }
long long GetOldPlaylistID() const { return isConnected && itsOldStatus ? itsOldStatus->playlist : -1; } long long GetOldPlaylistID() const { return isConnected && itsOldStatus ? itsOldStatus->playlist : -1; }
int GetElapsedTime() const { return isConnected && itsCurrentStatus ? itsCurrentStatus->elapsedTime : -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; } unsigned GetBitrate() const { return isConnected && itsCurrentStatus ? itsCurrentStatus->bitRate : 0; }
size_t GetMaxPlaylistLength() const { return itsMaxPlaylistLength; } size_t GetMaxPlaylistLength() const { return itsMaxPlaylistLength; }

View File

@@ -386,10 +386,9 @@ int main(int argc, char *argv[])
&& mouse_event.y == LINES-(Config.statusbar_visibility ? 2 : 1) && mouse_event.y == LINES-(Config.statusbar_visibility ? 2 : 1)
) // progressbar ) // progressbar
{ {
const Song *s = myPlaylist->NowPlayingSong(); if (!myPlaylist->isPlaying())
if (!s)
continue; continue;
Mpd.Seek(s->GetTotalLength()*mouse_event.x/double(COLS)); Mpd.Seek(Mpd.GetTotalTime()*mouse_event.x/double(COLS));
UpdateStatusImmediately = 1; UpdateStatusImmediately = 1;
} }
else if (mouse_event.bstate & BUTTON1_PRESSED 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)) else if (Keypressed(input, Key.SeekForward) || Keypressed(input, Key.SeekBackward))
{ {
const Song *s = myPlaylist->NowPlayingSong(); if (!Mpd.GetTotalTime())
if (!s)
continue;
if (!s->GetTotalLength())
{ {
ShowMessage("Unknown item length!"); ShowMessage("Unknown item length!");
continue; continue;
} }
const Song *s = myPlaylist->NowPlayingSong();
if (!s)
continue;
LockProgressbar(); LockProgressbar();
LockStatusbar(); 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; 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; songpos += howmuch;
if (songpos > s->GetTotalLength()) if (songpos > Mpd.GetTotalTime())
songpos = s->GetTotalLength(); songpos = Mpd.GetTotalTime();
} }
if (songpos < s->GetTotalLength() && songpos > 0 && Keypressed(input, Key.SeekBackward)) else if (Keypressed(input, Key.SeekBackward) && songpos > 0)
{ {
songpos -= howmuch; songpos -= howmuch;
if (songpos < 0) if (songpos < 0)
@@ -1138,12 +1137,12 @@ int main(int argc, char *argv[])
if (Config.display_remaining_time) if (Config.display_remaining_time)
{ {
tracklength = "-"; tracklength = "-";
tracklength += Song::ShowTime(s->GetTotalLength()-songpos); tracklength += Song::ShowTime(Mpd.GetTotalTime()-songpos);
} }
else else
tracklength = Song::ShowTime(songpos); tracklength = Song::ShowTime(songpos);
tracklength += "/"; tracklength += "/";
tracklength += s->GetLength(); tracklength += MPD::Song::ShowTime(Mpd.GetTotalTime());
*wHeader << XY(0, 0) << tracklength << " "; *wHeader << XY(0, 0) << tracklength << " ";
wHeader->Refresh(); wHeader->Refresh();
} }
@@ -1153,16 +1152,16 @@ int main(int argc, char *argv[])
if (Config.display_remaining_time) if (Config.display_remaining_time)
{ {
tracklength += "-"; tracklength += "-";
tracklength += Song::ShowTime(s->GetTotalLength()-songpos); tracklength += Song::ShowTime(Mpd.GetTotalTime()-songpos);
} }
else else
tracklength = Song::ShowTime(songpos); tracklength = Song::ShowTime(songpos);
tracklength += "/"; tracklength += "/";
tracklength += s->GetLength(); tracklength += MPD::Song::ShowTime(Mpd.GetTotalTime());
tracklength += "]"; tracklength += "]";
*wFooter << XY(wFooter->GetWidth()-tracklength.length(), 1) << 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; unsigned howlong = wFooter->GetWidth()*progressbar_size;
mvwhline(wFooter->Raw(), 0, 0, 0, wFooter->GetWidth()); mvwhline(wFooter->Raw(), 0, 0, 0, wFooter->GetWidth());
@@ -1488,16 +1487,16 @@ int main(int argc, char *argv[])
} }
else if (Keypressed(input, Key.GoToPosition)) else if (Keypressed(input, Key.GoToPosition))
{ {
const Song *s = myPlaylist->NowPlayingSong(); if (!Mpd.GetTotalTime())
if (!s)
continue;
if (!s->GetTotalLength())
{ {
ShowMessage("Unknown item length!"); ShowMessage("Unknown item length!");
continue; continue;
} }
const Song *s = myPlaylist->NowPlayingSong();
if (!s)
continue;
LockStatusbar(); LockStatusbar();
Statusbar() << "Position to go (in %/mm:ss/seconds(s)): "; Statusbar() << "Position to go (in %/mm:ss/seconds(s)): ";
std::string position = wFooter->GetString(); 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)); newpos = StrToInt(position)*60 + StrToInt(position.substr(position.find(':')+1));
} }
catch (std::out_of_range) { } catch (std::out_of_range) { }
if (newpos >= 0 && newpos <= s->GetTotalLength()) if (newpos >= 0 && newpos <= Mpd.GetTotalTime())
Mpd.Seek(newpos); Mpd.Seek(newpos);
else else
ShowMessage("Out of bounds, 0:00-%s possible for mm:ss, %s given.", s->GetLength().c_str(), MPD::Song::ShowTime(newpos).c_str()); 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 else if (position.find('s') != std::string::npos) // probably position in seconds
{ {
newpos = StrToInt(position); newpos = StrToInt(position);
if (newpos >= 0 && newpos <= s->GetTotalLength()) if (newpos >= 0 && newpos <= Mpd.GetTotalTime())
Mpd.Seek(newpos); Mpd.Seek(newpos);
else else
ShowMessage("Out of bounds, 0-%d possible for seconds, %d given.", s->GetTotalLength(), newpos); 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); newpos = StrToInt(position);
if (newpos >= 0 && newpos <= 100) if (newpos >= 0 && newpos <= 100)
Mpd.Seek(s->GetTotalLength()*newpos/100.0); Mpd.Seek(Mpd.GetTotalTime()*newpos/100.0);
else else
ShowMessage("Out of bounds, 0-100 possible for %%, %d given.", newpos); ShowMessage("Out of bounds, 0-100 possible for %%, %d given.", newpos);
} }

View File

@@ -415,14 +415,14 @@ void NcmpcppStatusChanged(Connection *, StatusChanges changed, void *)
if (Config.display_remaining_time) if (Config.display_remaining_time)
{ {
tracklength = "-"; tracklength = "-";
tracklength += Song::ShowTime(np.GetTotalLength()-elapsed); tracklength += Song::ShowTime(Mpd.GetTotalTime()-elapsed);
} }
else else
tracklength = Song::ShowTime(elapsed); tracklength = Song::ShowTime(elapsed);
if (np.GetTotalLength()) if (Mpd.GetTotalTime())
{ {
tracklength += "/"; tracklength += "/";
tracklength += np.GetLength(); tracklength += MPD::Song::ShowTime(Mpd.GetTotalTime());
} }
// bitrate here doesn't look good, but it can be moved somewhere else later // bitrate here doesn't look good, but it can be moved somewhere else later
if (Config.display_bitrate && Mpd.GetBitrate()) if (Config.display_bitrate && Mpd.GetBitrate())
@@ -466,17 +466,17 @@ void NcmpcppStatusChanged(Connection *, StatusChanges changed, void *)
tracklength += " kbps]"; tracklength += " kbps]";
} }
tracklength += " ["; tracklength += " [";
if (np.GetTotalLength()) if (Mpd.GetTotalTime())
{ {
if (Config.display_remaining_time) if (Config.display_remaining_time)
{ {
tracklength += "-"; tracklength += "-";
tracklength += Song::ShowTime(np.GetTotalLength()-elapsed); tracklength += Song::ShowTime(Mpd.GetTotalTime()-elapsed);
} }
else else
tracklength += Song::ShowTime(elapsed); tracklength += Song::ShowTime(elapsed);
tracklength += "/"; tracklength += "/";
tracklength += np.GetLength(); tracklength += MPD::Song::ShowTime(Mpd.GetTotalTime());
tracklength += "]"; tracklength += "]";
} }
else else
@@ -492,11 +492,11 @@ void NcmpcppStatusChanged(Connection *, StatusChanges changed, void *)
} }
if (!block_progressbar_update) if (!block_progressbar_update)
{ {
double progressbar_size = elapsed/double(np.GetTotalLength()); double progressbar_size = elapsed/double(Mpd.GetTotalTime());
unsigned howlong = wFooter->GetWidth()*progressbar_size; unsigned howlong = wFooter->GetWidth()*progressbar_size;
*wFooter << Config.progressbar_color; *wFooter << Config.progressbar_color;
mvwhline(wFooter->Raw(), 0, 0, 0, wFooter->GetWidth()); mvwhline(wFooter->Raw(), 0, 0, 0, wFooter->GetWidth());
if (np.GetTotalLength()) if (Mpd.GetTotalTime())
{ {
for (unsigned i = 0; i < howlong; ++i) for (unsigned i = 0; i < howlong; ++i)
*wFooter << Config.progressbar[0]; *wFooter << Config.progressbar[0];