Skip to content

Commit

Permalink
fix: rapid seek with fade in-out enabled may set volume to 0
Browse files Browse the repository at this point in the history
  • Loading branch information
mokurin000 committed Jan 16, 2024
1 parent e7994ff commit e2806e7
Showing 1 changed file with 13 additions and 20 deletions.
33 changes: 13 additions & 20 deletions feeluown/player/mpvplayer.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,6 @@ def set_play_range(self, start=None, end=None):
_mpv_set_option_string(self._mpv.handle, b'end', bytes(end_str, 'utf-8'))

def fade(self, fade_in: bool, max_volume=None, callback=None):
self.fade_lock.acquire()

# k: factor between 0 and 1, to represent tick/fade_time
def fade_curve(k: float, fade_in: bool) -> float:
if fade_in:
Expand All @@ -186,35 +184,30 @@ def set_volume(max_volume: int, fade_in: bool):
self.volume = new_volume
time.sleep(interval)

if max_volume:
volume = max_volume
else:
volume = self.volume
with self.fade_lock:
if max_volume:
volume = max_volume
else:
volume = self.volume

set_volume(volume, fade_in=fade_in)
set_volume(volume, fade_in=fade_in)

if callback is not None:
callback()
if callback is not None:
callback()

self.volume = volume
self.fade_lock.release()
self.volume = volume

def resume(self):
if self.do_fade:
_volume = self.volume
self.volume = 0

self._mpv.pause = False
self.state = State.playing

if self.do_fade:
fade_thread = Thread(
target=self.fade,
kwargs={"fade_in": True,
"max_volume": _volume}
kwargs={"fade_in": True}
)
fade_thread.start()

self._mpv.pause = False
self.state = State.playing

def _pause(self):
self._mpv.pause = True
self.state = State.paused
Expand Down

0 comments on commit e2806e7

Please sign in to comment.