Skip to content

Commit

Permalink
fix: rapid seek with fade in-out enabled may set volume to 0 (#768)
Browse files Browse the repository at this point in the history
  • Loading branch information
mokurin000 authored Jan 17, 2024
1 parent 10e8129 commit d8a4ea4
Showing 1 changed file with 11 additions and 22 deletions.
33 changes: 11 additions & 22 deletions feeluown/player/mpvplayer.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,7 @@ def set_play_range(self, start=None, end=None):
self.seeked.emit(start)
_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()

def fade(self, fade_in: bool, callback=None):
# 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,26 @@ 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

set_volume(volume, fade_in=fade_in)
with self.fade_lock:
max_volume = self.volume
set_volume(max_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 = max_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 d8a4ea4

Please sign in to comment.