Fixing error in starting playing songs that the Player lost reference to the current playing song

This commit is contained in:
Rafael Vargas 2023-01-24 19:42:57 -03:00
parent 7310eda1a1
commit 5cdc4e9a53
4 changed files with 7 additions and 4 deletions

View File

@ -14,6 +14,7 @@ from Parallelism.Commands import VCommands, VCommandsType
from Music.VulkanBot import VulkanBot from Music.VulkanBot import VulkanBot
from typing import Union from typing import Union
from discord import Interaction from discord import Interaction
from Music.Playlist import Playlist
class PlayHandler(AbstractHandler): class PlayHandler(AbstractHandler):
@ -38,7 +39,7 @@ class PlayHandler(AbstractHandler):
# Get the process context for the current guild # Get the process context for the current guild
processManager = self.config.getProcessManager() processManager = self.config.getProcessManager()
processInfo = processManager.getOrCreatePlayerInfo(self.guild, self.ctx) processInfo = processManager.getOrCreatePlayerInfo(self.guild, self.ctx)
playlist = processInfo.getPlaylist() playlist: Playlist = processInfo.getPlaylist()
process = processInfo.getProcess() process = processInfo.getProcess()
if not process.is_alive(): # If process has not yet started, start if not process.is_alive(): # If process has not yet started, start
process.start() process.start()

View File

@ -119,6 +119,7 @@ class PlayerProcess(Process):
if song is not None: if song is not None:
self.__loop.create_task(self.__playSong(song), name=f'Song {song.identifier}') self.__loop.create_task(self.__playSong(song), name=f'Song {song.identifier}')
self.__playing = True
async def __playSong(self, song: Song) -> None: async def __playSong(self, song: Song) -> None:
"""Function that will trigger the player to play the song""" """Function that will trigger the player to play the song"""
@ -139,7 +140,7 @@ class PlayerProcess(Process):
return return
self.__playing = True self.__playing = True
self.__playingSong = song self.__songPlaying = song
player = FFmpegPCMAudio(song.source, **self.FFMPEG_OPTIONS) player = FFmpegPCMAudio(song.source, **self.FFMPEG_OPTIONS)
self.__guild.voice_client.play(player, after=lambda e: self.__playNext(e)) self.__guild.voice_client.play(player, after=lambda e: self.__playNext(e))
@ -168,7 +169,7 @@ class PlayerProcess(Process):
self.__loop.create_task(self.__playSong(song), name=f'Song {song.identifier}') self.__loop.create_task(self.__playSong(song), name=f'Song {song.identifier}')
else: else:
self.__playlist.loop_off() self.__playlist.loop_off()
self.__playingSong = None self.__songPlaying = None
self.__playing = False self.__playing = False
# Send a command to the main process put this one to sleep # Send a command to the main process put this one to sleep
sleepCommand = VCommands(VCommandsType.SLEEPING) sleepCommand = VCommands(VCommandsType.SLEEPING)
@ -253,7 +254,7 @@ class PlayerProcess(Process):
sleepCommand = VCommands(VCommandsType.SLEEPING) sleepCommand = VCommands(VCommandsType.SLEEPING)
self.__queueSend.put(sleepCommand) self.__queueSend.put(sleepCommand)
self.__guild.voice_client.stop() self.__guild.voice_client.stop()
self.__playingSong = None self.__songPlaying = None
await self.__guild.voice_client.disconnect() await self.__guild.voice_client.disconnect()
self.__semStopPlaying.release() self.__semStopPlaying.release()

View File

@ -65,6 +65,7 @@ class ProcessManager(Singleton):
def getRunningPlayerInfo(self, guild: Guild) -> ProcessInfo: def getRunningPlayerInfo(self, guild: Guild) -> ProcessInfo:
"""Return the process info for the guild, if not, return None""" """Return the process info for the guild, if not, return None"""
if guild.id not in self.__playersProcess.keys(): if guild.id not in self.__playersProcess.keys():
print('Process Info not found')
return None return None
return self.__playersProcess[guild.id] return self.__playersProcess[guild.id]

Binary file not shown.