I'm trying to create a python program that loops the same clip until the user presses the esc key or closes the window.
I saw a question here that advised using moviepy with pygame, but the problem is when I am running a VideoFileClip preview, pygame.event.get()
doesn't seem to write events like it is supposed to.
When I press the exit button, the program just restarts the clip and doesn't even enter the for event in pygame.event.get():
loop at line 22. Any help is appreciated
from moviepy.editor import *
import pygame
import os
pygame.init()
clip = VideoFileClip('videos/nightRide.mp4')
pygame.display.set_caption("Melancholic Cat")
catImage = pygame.image.load("images/cat.png")
pygame.display.set_icon(catImage)
run = True
while run:
clip.preview()
pygame.display.init()
keys = pygame.key.get_pressed()
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
if keys[pygame.K_ESCAPE]:
run = False
pygame.display.quit()
pygame.quit()
sys.exit()