Refactor: Move SettingsWindow to settings_screen.py and use system VLC for video playback

This commit is contained in:
2025-08-22 21:58:18 +03:00
parent 41ff96065b
commit 47d9ec5779
10 changed files with 323 additions and 39 deletions

View File

@@ -5,7 +5,6 @@ This file acts as the main executable for launching the tkinter player.
"""
import os
import sys
import cv2 # Import OpenCV to confirm it's available
# Add the current directory to the path so we can import our modules
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
@@ -14,7 +13,6 @@ sys.path.append(os.path.dirname(os.path.abspath(__file__)))
from tkinter_simple_player import SimpleMediaPlayerApp
if __name__ == "__main__":
print(f"Using OpenCV version: {cv2.__version__}")
# Create and run the player
player = SimpleMediaPlayerApp()
player.run()

View File

@@ -0,0 +1,19 @@
# settings_screen.py
"""
SettingsWindow class and related settings UI logic for the Tkinter Simple Media Player.
"""
import tkinter as tk
from tkinter import ttk, messagebox
import os
import json
import requests
from logging_config import Logger
from python_functions import (
load_local_playlist, download_media_files, clean_unused_files,
save_local_playlist, update_config_playlist_version, fetch_server_playlist,
load_config
)
from virtual_keyboard import VirtualKeyboard, TouchOptimizedEntry, TouchOptimizedButton
# ...Paste the full SettingsWindow class here (from tkinter_simple_player.py)...

View File

@@ -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)