Untitled
unknown
plain_text
a year ago
2.0 kB
3
Indexable
import cv2 import json import datetime import time import pygame import numpy as np # Inicializa Pygame pygame.init() screen = pygame.display.set_mode((0, 0), pygame.FULLSCREEN) def load_media_schedule(): with open('schedule.json', 'r') as f: return json.load(f) def play_media(file_path, media_type): if media_type == "video": cap = cv2.VideoCapture(file_path) while cap.isOpened(): ret, frame = cap.read() if ret: frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB) frame = np.rot90(frame) frame = pygame.surfarray.make_surface(frame) for event in pygame.event.get(): if event.type == pygame.QUIT: cap.release() cv2.destroyAllWindows() return screen.blit(frame, (0, 0)) pygame.display.update() else: cap.set(cv2.CAP_PROP_POS_FRAMES, 0) # Re-loop the video elif media_type == "image": image = pygame.image.load(file_path) image_rect = image.get_rect(center=(screen.get_width()//2, screen.get_height()//2)) while True: for event in pygame.event.get(): if event.type == pygame.QUIT: return screen.blit(image, image_rect) pygame.display.update() time.sleep(0.1) # Update display every 0.1 seconds to keep the app responsive schedule = load_media_schedule() while True: current_time = datetime.datetime.now().time() for item in schedule["media"]: start_time = datetime.datetime.strptime(item["start_time"], '%H:%M').time() end_time = datetime.datetime.strptime(item["end_time"], '%H:%M').time() if start_time <= current_time <= end_time: play_media(item["file"], item["type"]) time.sleep(60) # Espera 60 segundos antes de revisar el horario nuevamente
Editor is loading...
Leave a Comment