diff --git a/src/Resurse/app_config.txt b/src/Resurse/app_config.txt index c8c68c3..68aba08 100644 --- a/src/Resurse/app_config.txt +++ b/src/Resurse/app_config.txt @@ -1 +1 @@ -{"screen_orientation": "Landscape", "screen_name": "TvHolBa1", "quickconnect_key": "Initial01!", "server_ip": "192.168.0.115", "port": "5000"} \ No newline at end of file +{"screen_orientation": "Landscape", "screen_name": "TvHolBa1", "quickconnect_key": "Initial01!", "server_ip": "192.168.0.115", "port": "80"} \ No newline at end of file diff --git a/src/__pycache__/python_functions.cpython-311.pyc b/src/__pycache__/python_functions.cpython-311.pyc index 3277728..a558a83 100644 Binary files a/src/__pycache__/python_functions.cpython-311.pyc and b/src/__pycache__/python_functions.cpython-311.pyc differ diff --git a/src/media_player.py b/src/media_player.py index e77c3bf..4869c22 100644 --- a/src/media_player.py +++ b/src/media_player.py @@ -2,111 +2,127 @@ from kivy.config import Config Config.set('kivy', 'video', 'ffpyplayer') # Set ffpyplayer as the video provider from kivy.app import App -from kivy.uix.screenmanager import ScreenManager, Screen -from kivy.clock import Clock -from kivy.core.window import Window -from kivy.uix.video import Video -from kivy.uix.image import Image -from kivy.logger import Logger -from kivy.lang import Builder -import os -import json +from kivy.uix.screenmanager import ScreenManager, Screen # Import ScreenManager and Screen for managing screens +from kivy.clock import Clock # Import Clock for scheduling tasks +from kivy.core.window import Window # Import Window for handling window events +from kivy.uix.video import Video # Import Video widget for video playback +from kivy.uix.image import Image # Import Image widget for displaying images +from kivy.logger import Logger # Import Logger for logging messages +from kivy.lang import Builder # Import Builder for loading KV files +import os # Import os for file and directory operations +import json # Import json for handling JSON data # Import functions from python_functions.py from python_functions import load_playlist, download_media_files, clean_unused_files -# Load the KV file +# Load the KV file for UI layout Builder.load_file('kv/media_player.kv') +# Path to the configuration file CONFIG_FILE = './Resurse/app_config.txt' class MediaPlayer(Screen): + """Main screen for media playback.""" + def __init__(self, **kwargs): super(MediaPlayer, self).__init__(**kwargs) - self.playlist = [] - self.current_index = 0 - self.video_player = self.ids.video_player - self.image_display = self.ids.image_display - Clock.schedule_interval(self.check_playlist_updates, 300) # Check for updates every 5 minutes + self.playlist = [] # Initialize the playlist + self.current_index = 0 # Index of the currently playing media + self.video_player = self.ids.video_player # Reference to the Video widget + self.image_display = self.ids.image_display # Reference to the Image widget + # Schedule periodic updates to check for playlist updates + Clock.schedule_interval(self.check_playlist_updates, 300) # Every 5 minutes + # Bind key events to handle fullscreen toggle Window.bind(on_key_down=self.on_key_down) - # Start a timer to hide the settings button + # Start a timer to hide the settings button after 10 seconds self.hide_button_timer = Clock.schedule_once(self.hide_settings_button, 10) def on_touch_down(self, touch): - # Reset the button visibility and restart the hide timer - self.ids.settings_button.opacity = 1 + """Handle touch events to reset the settings button visibility.""" + self.ids.settings_button.opacity = 1 # Make the settings button visible if hasattr(self, 'hide_button_timer'): - Clock.unschedule(self.hide_button_timer) - self.hide_button_timer = Clock.schedule_once(self.hide_settings_button, 10) + Clock.unschedule(self.hide_button_timer) # Cancel the existing hide timer + self.hide_button_timer = Clock.schedule_once(self.hide_settings_button, 10) # Restart the hide timer return super(MediaPlayer, self).on_touch_down(touch) def hide_settings_button(self, *args): - # Hide the settings button after inactivity + """Hide the settings button after inactivity.""" self.ids.settings_button.opacity = 0 def on_key_down(self, window, key, *args): + """Handle key events for toggling fullscreen mode.""" if key == 102: # 'f' key Window.fullscreen = not Window.fullscreen def on_enter(self): - self.playlist = load_playlist() - download_media_files(self.playlist) - clean_unused_files(self.playlist) # Clean up unused files - self.play_media() + """Called when the screen is entered.""" + self.playlist = load_playlist() # Load the playlist + download_media_files(self.playlist) # Download media files from the playlist + clean_unused_files(self.playlist) # Remove unused files from the resource folder + self.play_media() # Start playing media def play_media(self): + """Play the current media in the playlist.""" if self.playlist: - media = self.playlist[self.current_index] - file_name = media.get('file_name', '') - file_extension = os.path.splitext(file_name)[1].lower() - duration = media.get('duration', 10) # Default duration is 10 seconds + media = self.playlist[self.current_index] # Get the current media + file_name = media.get('file_name', '') # Get the file name + file_extension = os.path.splitext(file_name)[1].lower() # Get the file extension + duration = media.get('duration', 10) # Get the duration (default: 10 seconds) # Define the base directory for media files - base_dir = os.path.join(os.path.dirname(__file__), 'static', 'resurse') # Update this to the correct path - file_path = os.path.join(base_dir, file_name) + base_dir = os.path.join(os.path.dirname(__file__), 'static', 'resurse') + file_path = os.path.join(base_dir, file_name) # Full path to the media file Logger.info(f"Playing media: {file_path}") + # Determine the type of media and play it if file_extension in ['.mp4', '.avi', '.mov']: - self.play_video(file_path) + self.play_video(file_path) # Play video elif file_extension in ['.jpg', '.jpeg', '.png', '.gif']: - self.show_image(file_path, duration) + self.show_image(file_path, duration) # Show image else: Logger.error(f"Unsupported media type for file: {file_name}") def play_video(self, file_path): + """Play a video file.""" Logger.info(f"Playing video: {file_path}") - self.video_player.source = file_path - self.video_player.opacity = 1 - self.video_player.state = 'play' - self.image_display.opacity = 0 - Clock.schedule_once(self.next_media, self.video_player.duration) + self.video_player.source = file_path # Set the video source + self.video_player.opacity = 1 # Make the video player visible + self.video_player.state = 'play' # Start playing the video + self.image_display.opacity = 0 # Hide the image display + Clock.schedule_once(self.next_media, self.video_player.duration) # Schedule the next media def show_image(self, file_path, duration): + """Display an image.""" Logger.info(f"Showing image: {file_path}") - self.image_display.source = file_path - self.image_display.opacity = 1 - self.image_display.reload() - self.video_player.opacity = 0 - Clock.schedule_once(self.next_media, duration) + self.image_display.source = file_path # Set the image source + self.image_display.opacity = 1 # Make the image display visible + self.image_display.reload() # Reload the image + self.video_player.opacity = 0 # Hide the video player + Clock.schedule_once(self.next_media, duration) # Schedule the next media def next_media(self, dt): - self.current_index = (self.current_index + 1) % len(self.playlist) - self.play_media() + """Move to the next media in the playlist.""" + self.current_index = (self.current_index + 1) % len(self.playlist) # Increment the index + self.play_media() # Play the next media def check_playlist_updates(self, dt): - self.playlist = load_playlist() - download_media_files(self.playlist) - clean_unused_files(self.playlist) # Clean up unused files - self.play_media() + """Check for updates to the playlist.""" + self.playlist = load_playlist() # Reload the playlist + download_media_files(self.playlist) # Download new media files + clean_unused_files(self.playlist) # Remove unused files + self.play_media() # Restart media playback class SettingsScreen(Screen): + """Settings screen for configuring the app.""" + def __init__(self, **kwargs): super(SettingsScreen, self).__init__(**kwargs) - self.config_data = self.load_config() + self.config_data = self.load_config() # Load the configuration data def load_config(self): + """Load the configuration from the config file.""" if os.path.exists(CONFIG_FILE): with open(CONFIG_FILE, 'r') as file: return json.load(file) @@ -119,7 +135,7 @@ class SettingsScreen(Screen): } def save_config(self): - # Save the input values to the config file + """Save the configuration to the config file.""" self.config_data["screen_orientation"] = self.ids.orientation_input.text self.config_data["screen_name"] = self.ids.screen_name_input.text self.config_data["quickconnect_key"] = self.ids.quickconnect_key_input.text @@ -134,25 +150,27 @@ class SettingsScreen(Screen): self.manager.current = 'media_player' def on_pre_enter(self): - # Populate input fields with current config data + """Populate input fields with current config data.""" self.ids.orientation_input.text = self.config_data.get("screen_orientation", "landscape") self.ids.screen_name_input.text = self.config_data.get("screen_name", "") self.ids.quickconnect_key_input.text = self.config_data.get("quickconnect_key", "") self.ids.server_ip_input.text = self.config_data.get("server_ip", "") self.ids.port_input.text = self.config_data.get("port", "8080") - class MediaPlayerApp(App): + """Main application class.""" + def build(self): - Window.fullscreen = True - sm = ScreenManager() - sm.add_widget(MediaPlayer(name='media_player')) - sm.add_widget(SettingsScreen(name='settings')) + """Build the app and initialize screens.""" + Window.fullscreen = True # Start the app in fullscreen mode + sm = ScreenManager() # Create a screen manager + sm.add_widget(MediaPlayer(name='media_player')) # Add the MediaPlayer screen + sm.add_widget(SettingsScreen(name='settings')) # Add the SettingsScreen return sm def open_settings(self): + """Switch to the SettingsScreen.""" self.root.current = 'settings' - if __name__ == '__main__': - MediaPlayerApp().run() \ No newline at end of file + MediaPlayerApp().run() # Run the app \ No newline at end of file diff --git a/src/static/resurse/harting_contactor.jpg b/src/static/resurse/harting_contactor.jpg new file mode 100644 index 0000000..d188777 Binary files /dev/null and b/src/static/resurse/harting_contactor.jpg differ