diff --git a/feeluown/app/app.py b/feeluown/app/app.py index e935d46932..ff02a20ddd 100644 --- a/feeluown/app/app.py +++ b/feeluown/app/app.py @@ -59,7 +59,8 @@ def __init__(self, args, config, **kwargs): # Player. self.player = Player( audio_device=bytes(config.MPV_AUDIO_DEVICE, 'utf-8'), - fade=config.PLAYBACK_CROSSFADE + fade=config.PLAYBACK_CROSSFADE, + fade_time_ms=config.PLAYBACK_CROSSFADE_DURATION, ) # Theoretically, each caller maintain its own position delegate. # For simplicity, this delegate is created for common use cases and diff --git a/feeluown/app/config.py b/feeluown/app/config.py index 6c874a5304..8f4b7930ce 100644 --- a/feeluown/app/config.py +++ b/feeluown/app/config.py @@ -32,4 +32,6 @@ def create_config() -> Config: desc='切换歌曲时显示桌面通知') config.deffield('NOTIFY_DURATION', type_=int, default=3000, desc='桌面通知保留时长(ms)') config.deffield('PLAYBACK_CROSSFADE', type_=bool, default=False, desc='播放暂停淡入淡出') + config.deffield('PLAYBACK_CROSSFADE_DURATION', type_=int, + default=500, desc='淡入淡出持续时间') return config diff --git a/feeluown/player/mpvplayer.py b/feeluown/player/mpvplayer.py index a787551601..2f366f2473 100644 --- a/feeluown/player/mpvplayer.py +++ b/feeluown/player/mpvplayer.py @@ -32,7 +32,8 @@ class MpvPlayer(AbstractPlayer): todo: make me singleton """ - def __init__(self, _=None, audio_device=b'auto', winid=None, fade=False, **kwargs): + def __init__(self, _=None, audio_device=b'auto', winid=None, + fade=False, fade_time_ms=500, **kwargs): """ :param _: keep this arg to keep backward compatibility """ @@ -87,6 +88,7 @@ def __init__(self, _=None, audio_device=b'auto', winid=None, fade=False, **kwarg self.do_fade = fade if self.do_fade: self.fade_lock = RLock() + self.fade_time_ms = fade_time_ms def shutdown(self): # The mpv has already been terminated. @@ -171,12 +173,12 @@ def fade_curve(k: float, fade_in: bool) -> float: def set_volume(max_volume: int, fade_in: bool): # https://bugs.python.org/issue31539#msg302699 if os.name == "nt": - freq = 25 interval = 0.02 else: - freq = 50 interval = 0.01 + freq = int(self.fade_time_ms / 1000 / interval) + for _tick in range(freq): new_volume = math.ceil( fade_curve(_tick/freq, fade_in=fade_in)*max_volume