From 493f3075993375a2d1337055afc1cd7669817a5e Mon Sep 17 00:00:00 2001 From: ske087 Date: Fri, 21 Nov 2025 22:46:29 +0200 Subject: [PATCH] updated to play video --- requirements.txt | 1 + src/main.py | 45 ++++++++++++++------------------------------- 2 files changed, 15 insertions(+), 31 deletions(-) diff --git a/requirements.txt b/requirements.txt index ee1483f..0c88956 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,5 @@ kivy>=2.3.0 +ffpyplayer requests==2.32.4 bcrypt==4.2.1 aiohttp==3.9.1 diff --git a/src/main.py b/src/main.py index 63111e6..b29e2d2 100644 --- a/src/main.py +++ b/src/main.py @@ -403,8 +403,6 @@ class SignagePlayer(Widget): self.next_media() return - Logger.info(f"SignagePlayer: Playing {file_name} for {duration}s") - # Remove status label if showing self.ids.status_label.opacity = 0 @@ -465,10 +463,12 @@ class SignagePlayer(Widget): self.next_media() return + Logger.info(f"SignagePlayer: Loading video {os.path.basename(video_path)} for {duration}s") + # Create Video widget with optimized settings self.current_widget = Video( source=video_path, - state='stop', # Start stopped, then play after loaded + state='play', # Start playing immediately options={ 'eos': 'stop', # Stop at end of stream }, @@ -480,13 +480,13 @@ class SignagePlayer(Widget): # Bind to loaded and error events self.current_widget.bind(loaded=self._on_video_loaded) + self.current_widget.bind(on_eos=self._on_video_eos) # Add to content area self.ids.content_area.add_widget(self.current_widget) - Logger.info(f"SignagePlayer: Playing {os.path.basename(video_path)} for {duration}s") - # Wait a bit for video to load, then start playing - Clock.schedule_once(lambda dt: self._start_video_playback(duration), 0.5) + # Schedule next media after duration + Clock.schedule_once(self.next_media, duration) except Exception as e: Logger.error(f"SignagePlayer: Error playing video {video_path}: {e}") @@ -494,37 +494,20 @@ class SignagePlayer(Widget): if self.consecutive_errors < self.max_consecutive_errors: self.next_media() - def _start_video_playback(self, duration): - """Start video playback after widget is loaded""" - try: - if self.current_widget and hasattr(self.current_widget, 'state'): - self.current_widget.state = 'play' - Logger.info("SignagePlayer: Video playback started") - # Schedule next media after duration - Clock.schedule_once(self.next_media, duration) - else: - Logger.error("SignagePlayer: Video widget not ready") - self.next_media() - except Exception as e: - Logger.error(f"SignagePlayer: Error starting video playback: {e}") - self.next_media() - - def _on_video_error(self, instance, error): - """Callback when video encounters an error""" - Logger.error(f"Video playback error: {error}") - Logger.error(f"Video source: {instance.source}") - Logger.error(f"Video state: {instance.state}") - # Try to skip to next media on error - Clock.schedule_once(self.next_media, 1) + def _on_video_eos(self, instance): + """Callback when video reaches end of stream""" + Logger.info("SignagePlayer: Video finished playing (EOS)") def _on_video_loaded(self, instance, value): """Callback when video is loaded - log video information""" if value: try: - Logger.info(f"Video loaded: {instance.texture.size if instance.texture else 'No texture'}") - Logger.info(f"Video duration: {instance.duration}s") + Logger.info(f"SignagePlayer: Video loaded successfully") + Logger.info(f"SignagePlayer: Video texture: {instance.texture.size if instance.texture else 'No texture'}") + Logger.info(f"SignagePlayer: Video duration: {instance.duration}s") + Logger.info(f"SignagePlayer: Video state: {instance.state}") except Exception as e: - Logger.debug(f"Could not log video info: {e}") + Logger.warning(f"SignagePlayer: Could not log video info: {e}") def play_image(self, image_path, duration): """Play an image file"""