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