fix: glitch sound when stopping music
This commit is contained in:
parent
9692570ec2
commit
662396bcc5
@ -82,7 +82,7 @@ class BaseItem:
|
|||||||
|
|
||||||
def add_tags(self, tags):
|
def add_tags(self, tags):
|
||||||
for tag in tags:
|
for tag in tags:
|
||||||
if tag not in self.tags:
|
if tag and tag not in self.tags:
|
||||||
self.tags.append(tag)
|
self.tags.append(tag)
|
||||||
self.version += 1
|
self.version += 1
|
||||||
|
|
||||||
|
39
mumbleBot.py
39
mumbleBot.py
@ -66,6 +66,8 @@ class MumbleBot:
|
|||||||
self.read_pcm_size = 0
|
self.read_pcm_size = 0
|
||||||
# self.download_threads = []
|
# self.download_threads = []
|
||||||
self.wait_for_ready = False # flag for the loop are waiting for download to complete in the other thread
|
self.wait_for_ready = False # flag for the loop are waiting for download to complete in the other thread
|
||||||
|
self.on_killing = threading.Lock() # lock to acquire when killing ffmpeg thread is asked but ffmpeg is not
|
||||||
|
# killed yet
|
||||||
|
|
||||||
if var.config.getboolean("bot", "auto_check_update"):
|
if var.config.getboolean("bot", "auto_check_update"):
|
||||||
th = threading.Thread(target=self.check_update, name="UpdateThread")
|
th = threading.Thread(target=self.check_update, name="UpdateThread")
|
||||||
@ -156,21 +158,22 @@ class MumbleBot:
|
|||||||
|
|
||||||
# Set the CTRL+C shortcut
|
# Set the CTRL+C shortcut
|
||||||
def ctrl_caught(self, signal, frame):
|
def ctrl_caught(self, signal, frame):
|
||||||
|
|
||||||
self.log.info(
|
self.log.info(
|
||||||
"\nSIGINT caught, quitting, {} more to kill".format(2 - self.nb_exit))
|
"\nSIGINT caught, quitting, {} more to kill".format(2 - self.nb_exit))
|
||||||
self.exit = True
|
|
||||||
self.pause()
|
|
||||||
if self.nb_exit > 1:
|
|
||||||
self.log.info("Forced Quit")
|
|
||||||
sys.exit(0)
|
|
||||||
self.nb_exit += 1
|
|
||||||
|
|
||||||
if var.config.getboolean('bot', 'save_playlist', fallback=True) \
|
if var.config.getboolean('bot', 'save_playlist', fallback=True) \
|
||||||
and var.config.get("bot", "save_music_library", fallback=True):
|
and var.config.get("bot", "save_music_library", fallback=True):
|
||||||
self.log.info("bot: save playlist into database")
|
self.log.info("bot: save playlist into database")
|
||||||
var.playlist.save()
|
var.playlist.save()
|
||||||
|
|
||||||
|
if self.nb_exit > 1:
|
||||||
|
self.log.info("Forced Quit")
|
||||||
|
sys.exit(0)
|
||||||
|
self.nb_exit += 1
|
||||||
|
|
||||||
|
self.pause()
|
||||||
|
self.exit = True
|
||||||
|
|
||||||
def check_update(self):
|
def check_update(self):
|
||||||
self.log.debug("update: checking for updates...")
|
self.log.debug("update: checking for updates...")
|
||||||
new_version = util.new_release_version()
|
new_version = util.new_release_version()
|
||||||
@ -336,6 +339,9 @@ class MumbleBot:
|
|||||||
# =======================
|
# =======================
|
||||||
|
|
||||||
def launch_music(self, music_wrapper, start_from=0):
|
def launch_music(self, music_wrapper, start_from=0):
|
||||||
|
self.on_killing.acquire()
|
||||||
|
self.on_killing.release()
|
||||||
|
|
||||||
assert music_wrapper.is_ready()
|
assert music_wrapper.is_ready()
|
||||||
|
|
||||||
uri = music_wrapper.uri()
|
uri = music_wrapper.uri()
|
||||||
@ -527,6 +533,8 @@ class MumbleBot:
|
|||||||
if delta > 0.001:
|
if delta > 0.001:
|
||||||
if self.is_ducking and self.on_ducking:
|
if self.is_ducking and self.on_ducking:
|
||||||
self.volume = (self.volume - self.ducking_volume) * math.exp(- delta / 0.2) + self.ducking_volume
|
self.volume = (self.volume - self.ducking_volume) * math.exp(- delta / 0.2) + self.ducking_volume
|
||||||
|
elif self.on_killing.locked():
|
||||||
|
self.volume = self.volume_set - (self.volume_set - self.volume) * math.exp(- delta / 0.05)
|
||||||
else:
|
else:
|
||||||
self.volume = self.volume_set - (self.volume_set - self.volume) * math.exp(- delta / 0.5)
|
self.volume = self.volume_set - (self.volume_set - self.volume) * math.exp(- delta / 0.5)
|
||||||
|
|
||||||
@ -582,19 +590,26 @@ class MumbleBot:
|
|||||||
|
|
||||||
def interrupt(self):
|
def interrupt(self):
|
||||||
# Kill the ffmpeg thread
|
# Kill the ffmpeg thread
|
||||||
|
if not self.on_killing.locked():
|
||||||
|
self.on_killing.acquire()
|
||||||
if self.thread:
|
if self.thread:
|
||||||
|
volume_set = self.volume_set
|
||||||
|
self.volume_set = 0
|
||||||
|
|
||||||
|
while self.volume > 0.01: # Waiting for volume_cycle to gradually tune volume to 0.
|
||||||
|
time.sleep(0.01)
|
||||||
|
|
||||||
self.thread.kill()
|
self.thread.kill()
|
||||||
self.thread = None
|
self.thread = None
|
||||||
|
self.volume_set = volume_set
|
||||||
|
self.on_killing.release()
|
||||||
|
|
||||||
self.song_start_at = -1
|
self.song_start_at = -1
|
||||||
self.read_pcm_size = 0
|
self.read_pcm_size = 0
|
||||||
self.playhead = 0
|
|
||||||
|
|
||||||
def pause(self):
|
def pause(self):
|
||||||
# Kill the ffmpeg thread
|
# Kill the ffmpeg thread
|
||||||
if self.thread:
|
self.interrupt()
|
||||||
self.pause_at_id = var.playlist.current_item().id
|
|
||||||
self.thread.kill()
|
|
||||||
self.thread = None
|
|
||||||
self.is_pause = True
|
self.is_pause = True
|
||||||
self.song_start_at = -1
|
self.song_start_at = -1
|
||||||
self.log.info("bot: music paused at %.2f seconds." % self.playhead)
|
self.log.info("bot: music paused at %.2f seconds." % self.playhead)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user