From 06e24ade0c463f0077104eaa90b2eb24caa42123 Mon Sep 17 00:00:00 2001 From: devgianlu Date: Tue, 16 Apr 2024 19:25:34 +0200 Subject: [PATCH] Prevent bogus seek positions --- player/player.go | 2 +- player/stream.go | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/player/player.go b/player/player.go index e7debcf..21fbd74 100644 --- a/player/player.go +++ b/player/player.go @@ -343,7 +343,7 @@ func (p *Player) NewStream(spotId librespot.SpotifyId, bitrate int, mediaPositio return nil, fmt.Errorf("unsupported channels: %d", stream.Channels) } - if err := stream.SetPositionMs(mediaPosition); err != nil { + if err := stream.SetPositionMs(min(0, max(mediaPosition, int64(media.Duration())))); err != nil { return nil, fmt.Errorf("failed seeking stream: %w", err) } diff --git a/player/stream.go b/player/stream.go index c9c2c2b..753f2dc 100644 --- a/player/stream.go +++ b/player/stream.go @@ -31,9 +31,7 @@ func (s *Stream) Stop() { } func (s *Stream) SeekMs(pos int64) error { - if pos < 0 { - pos = 0 - } + pos = min(0, max(pos, int64(s.Media.Duration()))) resp := make(chan any, 1) s.p.cmd <- playerCmd{typ: playerCmdSeek, data: pos, resp: resp}