updated player
This commit is contained in:
51
src/main.py
51
src/main.py
@@ -395,33 +395,58 @@ class SignagePlayer(Widget):
|
||||
file_name = media_item.get('file_name', '')
|
||||
duration = media_item.get('duration', 10)
|
||||
|
||||
Logger.info(f"SignagePlayer: ===== Playing item {self.current_index + 1}/{len(self.playlist)} =====")
|
||||
Logger.info(f"SignagePlayer: File: {file_name}")
|
||||
Logger.info(f"SignagePlayer: Duration: {duration}s")
|
||||
|
||||
# Construct full path to media file
|
||||
media_path = os.path.join(self.media_dir, file_name)
|
||||
Logger.info(f"SignagePlayer: Full path: {media_path}")
|
||||
|
||||
if not os.path.exists(media_path):
|
||||
Logger.error(f"SignagePlayer: Media file not found: {media_path}")
|
||||
Logger.error(f"SignagePlayer: ❌ Media file not found: {media_path}")
|
||||
Logger.error(f"SignagePlayer: Skipping to next media...")
|
||||
self.consecutive_errors += 1
|
||||
self.next_media()
|
||||
return
|
||||
|
||||
Logger.info(f"SignagePlayer: ✓ File exists (size: {os.path.getsize(media_path):,} bytes)")
|
||||
|
||||
# Remove status label if showing
|
||||
self.ids.status_label.opacity = 0
|
||||
|
||||
# Remove previous media widget
|
||||
if self.current_widget:
|
||||
# Properly stop video if it's playing to prevent resource leaks
|
||||
if isinstance(self.current_widget, Video):
|
||||
try:
|
||||
Logger.info(f"SignagePlayer: Stopping previous video widget...")
|
||||
self.current_widget.state = 'stop'
|
||||
self.current_widget.unload()
|
||||
except Exception as e:
|
||||
Logger.warning(f"SignagePlayer: Error stopping video: {e}")
|
||||
|
||||
self.ids.content_area.remove_widget(self.current_widget)
|
||||
self.current_widget = None
|
||||
Logger.info(f"SignagePlayer: Previous widget removed")
|
||||
|
||||
# Determine media type and create appropriate widget
|
||||
file_extension = os.path.splitext(file_name)[1].lower()
|
||||
Logger.info(f"SignagePlayer: Extension: {file_extension}")
|
||||
|
||||
if file_extension in ['.mp4', '.avi', '.mkv', '.mov', '.webm']:
|
||||
# Video file
|
||||
Logger.info(f"SignagePlayer: Media type: VIDEO")
|
||||
self.play_video(media_path, duration)
|
||||
elif file_extension in ['.jpg', '.jpeg', '.png', '.bmp', '.gif']:
|
||||
# Image file
|
||||
Logger.info(f"SignagePlayer: Media type: IMAGE")
|
||||
self.play_image(media_path, duration)
|
||||
else:
|
||||
Logger.warning(f"SignagePlayer: Unsupported media type: {file_extension}")
|
||||
Logger.warning(f"SignagePlayer: ❌ Unsupported media type: {file_extension}")
|
||||
Logger.warning(f"SignagePlayer: Supported: .mp4/.avi/.mkv/.mov/.webm/.jpg/.jpeg/.png/.bmp/.gif")
|
||||
Logger.warning(f"SignagePlayer: Skipping to next media...")
|
||||
self.consecutive_errors += 1
|
||||
self.next_media()
|
||||
return
|
||||
|
||||
@@ -438,6 +463,7 @@ class SignagePlayer(Widget):
|
||||
|
||||
# Reset error counter on successful playback
|
||||
self.consecutive_errors = 0
|
||||
Logger.info(f"SignagePlayer: ✓ Media started successfully (consecutive_errors reset to 0)")
|
||||
|
||||
except Exception as e:
|
||||
Logger.error(f"SignagePlayer: Error playing media: {e}")
|
||||
@@ -459,13 +485,16 @@ class SignagePlayer(Widget):
|
||||
try:
|
||||
# Verify file exists
|
||||
if not os.path.exists(video_path):
|
||||
Logger.error(f"Video file not found: {video_path}")
|
||||
Logger.error(f"SignagePlayer: ❌ Video file not found: {video_path}")
|
||||
self.consecutive_errors += 1
|
||||
self.next_media()
|
||||
return
|
||||
|
||||
Logger.info(f"SignagePlayer: Loading video {os.path.basename(video_path)} for {duration}s")
|
||||
Logger.info(f"SignagePlayer: Video provider: {os.environ.get('KIVY_VIDEO', 'default')}")
|
||||
|
||||
# Create Video widget with optimized settings
|
||||
Logger.info(f"SignagePlayer: Creating Video widget...")
|
||||
self.current_widget = Video(
|
||||
source=video_path,
|
||||
state='play', # Start playing immediately
|
||||
@@ -483,9 +512,12 @@ class SignagePlayer(Widget):
|
||||
self.current_widget.bind(on_eos=self._on_video_eos)
|
||||
|
||||
# Add to content area
|
||||
Logger.info(f"SignagePlayer: Adding video widget to content area...")
|
||||
self.ids.content_area.add_widget(self.current_widget)
|
||||
|
||||
# Schedule next media after duration
|
||||
# Schedule next media after duration (unschedule first to prevent overlaps)
|
||||
Logger.info(f"SignagePlayer: Scheduled next media in {duration}s")
|
||||
Clock.unschedule(self.next_media)
|
||||
Clock.schedule_once(self.next_media, duration)
|
||||
|
||||
except Exception as e:
|
||||
@@ -512,6 +544,7 @@ class SignagePlayer(Widget):
|
||||
def play_image(self, image_path, duration):
|
||||
"""Play an image file"""
|
||||
try:
|
||||
Logger.info(f"SignagePlayer: Creating AsyncImage widget...")
|
||||
self.current_widget = AsyncImage(
|
||||
source=image_path,
|
||||
allow_stretch=True,
|
||||
@@ -519,9 +552,13 @@ class SignagePlayer(Widget):
|
||||
size_hint=(1, 1),
|
||||
pos_hint={'center_x': 0.5, 'center_y': 0.5}
|
||||
)
|
||||
Logger.info(f"SignagePlayer: Adding image widget to content area...")
|
||||
self.ids.content_area.add_widget(self.current_widget)
|
||||
# Schedule next media after duration
|
||||
# Schedule next media after duration (unschedule first to prevent overlaps)
|
||||
Logger.info(f"SignagePlayer: Scheduled next media in {duration}s")
|
||||
Clock.unschedule(self.next_media)
|
||||
Clock.schedule_once(self.next_media, duration)
|
||||
Logger.info(f"SignagePlayer: ✓ Image displayed successfully")
|
||||
except Exception as e:
|
||||
Logger.error(f"SignagePlayer: Error playing image {image_path}: {e}")
|
||||
self.consecutive_errors += 1
|
||||
@@ -531,8 +568,10 @@ class SignagePlayer(Widget):
|
||||
def next_media(self, dt=None):
|
||||
"""Move to next media item"""
|
||||
if self.is_paused:
|
||||
Logger.debug(f"SignagePlayer: Skipping next_media - player is paused")
|
||||
return
|
||||
|
||||
|
||||
Logger.info(f"SignagePlayer: Transitioning to next media (was index {self.current_index})")
|
||||
self.current_index += 1
|
||||
|
||||
# Unschedule any pending media transitions
|
||||
|
||||
Reference in New Issue
Block a user