Python 使用Pygame一个接一个地播放视频
我编写了一些Python代码,试图在Pygame中一个接一个地显示我想要显示的视频:Python 使用Pygame一个接一个地播放视频,python,video,pygame,Python,Video,Pygame,我编写了一些Python代码,试图在Pygame中一个接一个地显示我想要显示的视频: import pygame import time def playvid(vidfile, runtime, FPS): print("playing" + vidfile) playmovie = pygame.movie.Movie(vidfile) movie_screen = pygame.Surface(playmovie.get_size()).convert()
import pygame
import time
def playvid(vidfile, runtime, FPS):
print("playing" + vidfile)
playmovie = pygame.movie.Movie(vidfile)
movie_screen = pygame.Surface(playmovie.get_size()).convert()
playmovie.set_display(movie_screen)
playmovie.play()
thentime = time.time()
playing = True
while playing:
screen.blit(movie_screen,(0,0))
pygame.display.update()
clock.tick(FPS)
nowtime = time.time()
#Play the video for 5s
if nowtime - thentime > runtime + 1: playing = False
print("done this one")
#FPS = 29.97
pygame.init()
clock = pygame.time.Clock()
screen = pygame.display.set_mode((0, 0),pygame.FULLSCREEN)
run = True
while run:
playvid('snowdone.mpg', 10, 29.97)
playvid('snowdone1.mpg', 10, 29.97)
run = False
pygame.quit()
播放第一个视频可以,但播放第二个视频会发出警告:
运行时错误
程序:C:\Python27\pythonw.exe
此应用程序已请求运行时以异常方式终止它。
有关更多信息,请联系应用程序的支持团队
这两个视频播放自己的罚款,所以这不是一个mpg的问题。有什么建议吗?我不知道我所建议的改变有效的具体原因,但显然有效 按原样使用代码,我的第一部电影不会运行超过4-5秒,无论它总是在大致相同的点停止,然后pygame窗口将崩溃 在whileplaying循环中添加一段简单的pygame.event.get代码,但是修复了所有问题
while playing:
for event in pygame.event.get():
pass
screen.blit(movie_screen,(0,0))
pygame.display.update()
clock.tick(FPS)
nowtime = time.time()
#Play the video for 5s
if nowtime - thentime > runtime + 1: playing = False
奇怪的是,即使在事件的循环中什么都不做,代码也会毫无问题地运行