Commit 0f2a7226 authored by Max Kellermann's avatar Max Kellermann

PlayerControl: use std::chrono::duration for Seek()

parent f8d0ebe9
...@@ -221,7 +221,7 @@ PlayerControl::EnqueueSong(DetachedSong *song) ...@@ -221,7 +221,7 @@ PlayerControl::EnqueueSong(DetachedSong *song)
} }
bool bool
PlayerControl::Seek(DetachedSong *song, float seek_time) PlayerControl::Seek(DetachedSong *song, SongTime t)
{ {
assert(song != nullptr); assert(song != nullptr);
...@@ -229,7 +229,7 @@ PlayerControl::Seek(DetachedSong *song, float seek_time) ...@@ -229,7 +229,7 @@ PlayerControl::Seek(DetachedSong *song, float seek_time)
delete next_song; delete next_song;
next_song = song; next_song = song;
seek_where = seek_time; seek_time = t;
SynchronousCommand(PlayerCommand::SEEK); SynchronousCommand(PlayerCommand::SEEK);
Unlock(); Unlock();
......
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#include "thread/Thread.hxx" #include "thread/Thread.hxx"
#include "util/Error.hxx" #include "util/Error.hxx"
#include "CrossFade.hxx" #include "CrossFade.hxx"
#include "Chrono.hxx"
#include <stdint.h> #include <stdint.h>
...@@ -161,7 +162,7 @@ struct PlayerControl { ...@@ -161,7 +162,7 @@ struct PlayerControl {
*/ */
DetachedSong *next_song; DetachedSong *next_song;
double seek_where; SongTime seek_time;
CrossFadeSettings cross_fade; CrossFadeSettings cross_fade;
...@@ -434,7 +435,7 @@ public: ...@@ -434,7 +435,7 @@ public:
* @return true on success, false on failure (e.g. if MPD isn't * @return true on success, false on failure (e.g. if MPD isn't
* playing currently) * playing currently)
*/ */
bool Seek(DetachedSong *song, float seek_time); bool Seek(DetachedSong *song, SongTime t);
void SetCrossFade(float cross_fade_seconds); void SetCrossFade(float cross_fade_seconds);
......
...@@ -293,7 +293,7 @@ Player::StartDecoder(MusicPipe &_pipe) ...@@ -293,7 +293,7 @@ Player::StartDecoder(MusicPipe &_pipe)
unsigned start_ms = pc.next_song->GetStartMS(); unsigned start_ms = pc.next_song->GetStartMS();
if (pc.command == PlayerCommand::SEEK) if (pc.command == PlayerCommand::SEEK)
start_ms += (unsigned)(pc.seek_where * 1000); start_ms += pc.seek_time.ToMS();
dc.Start(new DetachedSong(*pc.next_song), dc.Start(new DetachedSong(*pc.next_song),
start_ms, pc.next_song->GetEndMS(), start_ms, pc.next_song->GetEndMS(),
...@@ -561,19 +561,20 @@ Player::SeekDecoder() ...@@ -561,19 +561,20 @@ Player::SeekDecoder()
/* send the SEEK command */ /* send the SEEK command */
double where = pc.seek_where; SongTime where = pc.seek_time;
if (pc.total_time > 0 && where > pc.total_time) if (pc.total_time > 0) {
where = pc.total_time - 0.1; const SongTime total_time = SongTime::FromS(pc.total_time);
if (where < 0.0) if (where > total_time)
where = 0.0; where = total_time;
}
if (!dc.Seek(SongTime::FromS(where) + SongTime::FromMS(start_ms))) { if (!dc.Seek(where + SongTime::FromMS(start_ms))) {
/* decoder failure */ /* decoder failure */
player_command_finished(pc); player_command_finished(pc);
return false; return false;
} }
elapsed_time = where; elapsed_time = where.ToDoubleS();
player_command_finished(pc); player_command_finished(pc);
...@@ -923,7 +924,7 @@ Player::Run() ...@@ -923,7 +924,7 @@ Player::Run()
pc.state = PlayerState::PLAY; pc.state = PlayerState::PLAY;
if (pc.command == PlayerCommand::SEEK) if (pc.command == PlayerCommand::SEEK)
elapsed_time = pc.seek_where; elapsed_time = pc.seek_time.ToDoubleS();
pc.CommandFinished(); pc.CommandFinished();
......
...@@ -215,7 +215,8 @@ playlist::SeekSongPosition(PlayerControl &pc, unsigned song, float seek_time) ...@@ -215,7 +215,8 @@ playlist::SeekSongPosition(PlayerControl &pc, unsigned song, float seek_time)
queued_song = nullptr; queued_song = nullptr;
} }
if (!pc.Seek(new DetachedSong(queue.GetOrder(i)), seek_time)) { if (!pc.Seek(new DetachedSong(queue.GetOrder(i)),
SongTime::FromS(seek_time))) {
UpdateQueuedSong(pc, queued_song); UpdateQueuedSong(pc, queued_song);
return PlaylistResult::NOT_PLAYING; return PlaylistResult::NOT_PLAYING;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment