1

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()
  • Remove [`pygame.display.init()`](https://www.pygame.org/docs/ref/display.html#pygame.display.init) from the loop, but add [`pygame.display.flip()`](https://www.pygame.org/docs/ref/display.html#pygame.display.flip) – Rabbid76 Sep 15 '20 at 14:23
  • @Rabbid76 I replaced ```pygame.display.init()``` with ```pygame.display.flip()``` and it still won't close – Anthony Karounis Sep 15 '20 at 14:26

0 Answers0