Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 18 additions & 8 deletions player.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import os
import random
import time
from subprocess import PIPE, Popen, STDOUT

directory = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'videos')
log_file = '/home/pi/video_log.txt' # Change this to your preferred log file path

videos = []

def log_video(video_name, reason):
timestamp = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime()) # Get timestamp
with open(log_file, 'a') as log: # Append to log file
log.write("[{}] {} - {}\n".format(timestamp, video_name, reason))

def getVideos():
global videos
Expand All @@ -15,18 +19,24 @@ def getVideos():
if file.lower().endswith('.mp4'):
videos.append(os.path.join(directory, file))


def playVideos():
global videos
if len(videos) == 0:
getVideos()
time.sleep(5)
return
random.shuffle(videos)
videos.sort()
for video in videos:
playProcess = Popen(['omxplayer', '--no-osd', '--aspect-mode', 'fill', video])
playProcess.wait()


while (True):
start_time = time.time() # Record start time
try:
playProcess = Popen(['omxplayer', '--no-osd', '--aspect-mode', 'fill', video])
playProcess.wait()
end_time = time.time() # Record end time
play_duration = end_time - start_time # Calculate duration
if play_duration < 30: # If video played for less than 30 seconds
log_video(video, 'played for less than 30 seconds')
except Exception as e:
log_video(video, 'failed to play: {}'.format(str(e))) # Log any error during play

while True:
playVideos()