Getting Started with Raspberry Pi

Page 72

import pygame from time import sleep pygame.init() screen = pygame.display.set_mode((320,240)) movie = pygame.movie.Movie("foo.mpg") movie.play() while True: if not(movie.get_busy()): print("rewind") movie.rewind() movie.play() if pygame.QUIT in [e.type for e in pygame.event.get()]: break

If the video has an audio track you’ll need to close Pygame’s audio mixer before playing the movie. To tell the mixer to quit include this line before you play: pygame.mixer.quit()

Even More Examples There’s a whole Pygame module dedicated to more complete example programs: pygame.examples. You can find the source code for these examples in the /usr/share/pyshared/pygame/ examples directory.

Further Reading Pygame official documentation The official documentation is a bit sparse in places, but hopefully you’ll be able to navigate it after reading this chapter. Making Games with Python & Pygame and Invent Your Own Computer Games with Python by Al Sweigart Two Creative Commons-licensed books; the games developed in these books are bundled with the Raspberry Pi.

56

Getting Started with Raspberry Pi


Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.