我正在Pygame中构建一个应用,该应用需要播放视频。视频为30 FPS。这是我正在运行的代码:
import pygame
filename = "foo/bar.mpg"
FPS = 30
pygame.init()
clock = pygame.time.Clock()
movie = pygame.movie.Movie(filename)
screen = pygame.display.set_mode(movie.get_size())
movie_screen = pygame.Surface(movie.get_size()).convert()
movie.set_display(movie_screen)
movie.play()
playing = True
while playing:
for event in pygame.event.get():
if event.type == pygame.QUIT:
movie.stop()
playing = False
screen.blit(movie_screen, (0, 0))
pygame.display.update()
clock.tick(FPS)
pygame.quit()
我从另一个StackOverflow页面上获得了此代码:How to load and play a video in pygame
当我运行此代码时,它将引发以下错误:
Traceback (most recent call last):
File "D:\Programming\Python\GWD\code\play_video.py", line 20, in play_video
movie.set_display(movie_screen)
TypeError: destination must be a Surface
movie_screen
变量是Pygame曲面。 (我将其类型打印到控制台上,并得到<type 'pygame.Surface'>
)
我正在使用Python 2.7.10和Pygame 1.9.3。 如果您需要任何其他信息,请随时询问。