Replace pygame with playsound3 for audio notifications
Switched from pygame to playsound3 for playing notification sounds in the GUI. Updated requirements.txt and refactored related code to use playsound3, improving compatibility and simplifying sound playback.
This commit is contained in:
+1
-1
@@ -4,6 +4,6 @@ requests
|
|||||||
pillow
|
pillow
|
||||||
packaging
|
packaging
|
||||||
markdown
|
markdown
|
||||||
pygame
|
playsound3
|
||||||
loguru
|
loguru
|
||||||
setuptools
|
setuptools
|
||||||
+12
-19
@@ -55,11 +55,10 @@ except ImportError:
|
|||||||
YT_DLP_AVAILABLE = False
|
YT_DLP_AVAILABLE = False
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import pygame
|
from playsound3 import playsound
|
||||||
|
PLAYSOUND_AVAILABLE = True
|
||||||
PYGAME_AVAILABLE = True
|
|
||||||
except ImportError:
|
except ImportError:
|
||||||
PYGAME_AVAILABLE = False
|
PLAYSOUND_AVAILABLE = False
|
||||||
|
|
||||||
|
|
||||||
class YTSageApp(QMainWindow, FormatTableMixin, VideoInfoMixin): # Inherit from mixins
|
class YTSageApp(QMainWindow, FormatTableMixin, VideoInfoMixin): # Inherit from mixins
|
||||||
@@ -72,8 +71,8 @@ class YTSageApp(QMainWindow, FormatTableMixin, VideoInfoMixin): # Inherit from
|
|||||||
# Log startup warnings for missing dependencies
|
# Log startup warnings for missing dependencies
|
||||||
if not YT_DLP_AVAILABLE:
|
if not YT_DLP_AVAILABLE:
|
||||||
self.logger.warning("yt-dlp not available at startup, will be downloaded at runtime")
|
self.logger.warning("yt-dlp not available at startup, will be downloaded at runtime")
|
||||||
if not PYGAME_AVAILABLE:
|
if not PLAYSOUND_AVAILABLE:
|
||||||
self.logger.warning("pygame not available, audio notifications disabled")
|
self.logger.warning("playsound3 not available, audio notifications disabled")
|
||||||
|
|
||||||
# Check for FFmpeg before proceeding
|
# Check for FFmpeg before proceeding
|
||||||
if not check_ffmpeg():
|
if not check_ffmpeg():
|
||||||
@@ -305,14 +304,13 @@ class YTSageApp(QMainWindow, FormatTableMixin, VideoInfoMixin): # Inherit from
|
|||||||
# Initialize UI state based on current mode
|
# Initialize UI state based on current mode
|
||||||
self.handle_mode_change()
|
self.handle_mode_change()
|
||||||
|
|
||||||
# Initialize pygame for sound notifications
|
# Initialize playsound3 for sound notifications
|
||||||
self.init_sound()
|
self.init_sound()
|
||||||
|
|
||||||
def init_sound(self) -> None:
|
def init_sound(self) -> None:
|
||||||
"""Initialize pygame mixer for sound notifications"""
|
"""Initialize playsound3 for sound notifications"""
|
||||||
try:
|
try:
|
||||||
if PYGAME_AVAILABLE:
|
if PLAYSOUND_AVAILABLE:
|
||||||
pygame.mixer.init()
|
|
||||||
self.sound_enabled = True
|
self.sound_enabled = True
|
||||||
|
|
||||||
# sound_path logic moved to src\utils\ytsage_constants.py
|
# sound_path logic moved to src\utils\ytsage_constants.py
|
||||||
@@ -326,7 +324,7 @@ class YTSageApp(QMainWindow, FormatTableMixin, VideoInfoMixin): # Inherit from
|
|||||||
self.logger.info(f"Notification sound loaded from: {self.notification_sound_path}")
|
self.logger.info(f"Notification sound loaded from: {self.notification_sound_path}")
|
||||||
else:
|
else:
|
||||||
self.sound_enabled = False
|
self.sound_enabled = False
|
||||||
self.logger.info("Sound notifications disabled - pygame not available")
|
self.logger.info("Sound notifications disabled - playsound3 not available")
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.logger.error(f"Error initializing sound: {e}")
|
self.logger.error(f"Error initializing sound: {e}")
|
||||||
@@ -339,14 +337,9 @@ class YTSageApp(QMainWindow, FormatTableMixin, VideoInfoMixin): # Inherit from
|
|||||||
|
|
||||||
def play_sound() -> None:
|
def play_sound() -> None:
|
||||||
try:
|
try:
|
||||||
if PYGAME_AVAILABLE:
|
if PLAYSOUND_AVAILABLE:
|
||||||
# Load and play the sound
|
# Play the sound using playsound3
|
||||||
pygame.mixer.music.load(self.notification_sound_path)
|
playsound(str(self.notification_sound_path))
|
||||||
pygame.mixer.music.play()
|
|
||||||
|
|
||||||
# Wait for the sound to finish playing
|
|
||||||
while pygame.mixer.music.get_busy():
|
|
||||||
pygame.time.wait(100)
|
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.logger.error(f"Error playing notification sound: {e}")
|
self.logger.error(f"Error playing notification sound: {e}")
|
||||||
|
|||||||
Reference in New Issue
Block a user