Refactor: Move SettingsWindow to settings_screen.py and use system VLC for video playback
This commit is contained in:
@@ -21,8 +21,7 @@ import subprocess
|
||||
import sys
|
||||
import requests # Required for server communication
|
||||
import queue
|
||||
import cv2 # For video playback
|
||||
import pygame # For video audio
|
||||
import vlc # For video playback with hardware acceleration
|
||||
|
||||
# Try importing PIL but provide fallback
|
||||
try:
|
||||
@@ -73,12 +72,7 @@ class SimpleMediaPlayerApp:
|
||||
# Display scaling mode ('fit', 'fill', 'stretch')
|
||||
self.scaling_mode = 'fit' # Default to fit (maintain aspect ratio with black bars)
|
||||
|
||||
# Initialize pygame for video audio
|
||||
try:
|
||||
pygame.init()
|
||||
pygame.mixer.init()
|
||||
except Exception as e:
|
||||
Logger.warning(f"Failed to initialize pygame mixer for audio: {e}")
|
||||
# VLC will be used for video/audio playback (no pygame needed)
|
||||
|
||||
self.setup_ui()
|
||||
|
||||
@@ -533,34 +527,29 @@ class SimpleMediaPlayerApp:
|
||||
self.auto_advance_timer = self.root.after(5000, self.next_media)
|
||||
|
||||
def play_video(self, file_path):
|
||||
"""Play video file using python-vlc-wrapper for robust hardware acceleration."""
|
||||
"""Play video file using system VLC as a subprocess for robust hardware acceleration and stability."""
|
||||
self.status_label.place_forget()
|
||||
def run_vlc():
|
||||
def run_vlc_subprocess():
|
||||
try:
|
||||
Logger.info(f"Starting VLC for video: {file_path}")
|
||||
import vlc
|
||||
instance = vlc.Instance('--no-osd', '--no-video-title-show', '--intf', 'dummy', '--no-video-deco', '--no-embedded-video', '--quiet')
|
||||
player = instance.media_player_new()
|
||||
media = instance.media_new(file_path)
|
||||
player.set_media(media)
|
||||
player.play()
|
||||
time.sleep(0.5)
|
||||
try:
|
||||
player.set_fullscreen(True)
|
||||
except Exception as e:
|
||||
Logger.warning(f"Could not set VLC fullscreen: {e}")
|
||||
while True:
|
||||
state = player.get_state()
|
||||
if state in [vlc.State.Ended, vlc.State.Error, vlc.State.Stopped]:
|
||||
break
|
||||
time.sleep(0.5)
|
||||
player.stop()
|
||||
Logger.info(f"VLC finished: {file_path}")
|
||||
Logger.info(f"Starting system VLC subprocess for video: {file_path}")
|
||||
# Build VLC command
|
||||
vlc_cmd = [
|
||||
'cvlc',
|
||||
'--fullscreen',
|
||||
'--no-osd',
|
||||
'--no-video-title-show',
|
||||
'--play-and-exit',
|
||||
'--quiet',
|
||||
file_path
|
||||
]
|
||||
proc = subprocess.Popen(vlc_cmd, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
||||
proc.wait()
|
||||
Logger.info(f"VLC subprocess finished: {file_path}")
|
||||
except Exception as e:
|
||||
Logger.error(f"VLC error: {e}")
|
||||
Logger.error(f"VLC subprocess error: {e}")
|
||||
finally:
|
||||
self.root.after_idle(lambda: setattr(self, 'auto_advance_timer', self.root.after(1000, self.next_media)))
|
||||
threading.Thread(target=run_vlc, daemon=True).start()
|
||||
threading.Thread(target=run_vlc_subprocess, daemon=True).start()
|
||||
|
||||
def _update_video_frame(self, photo):
|
||||
"""Update video frame from main thread"""
|
||||
@@ -1311,7 +1300,7 @@ class SettingsWindow:
|
||||
|
||||
self.hardware_accel_var = tk.BooleanVar(value=True)
|
||||
self.create_checkbox(perf_card, "Enable hardware acceleration", self.hardware_accel_var)
|
||||
|
||||
self.settings_window = SettingsWindow(self.root, self, dark_theme=True)
|
||||
self.cache_media_var = tk.BooleanVar(value=True)
|
||||
self.create_checkbox(perf_card, "Cache media files locally", self.cache_media_var)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user