
- Pygame Tutorial
- Pygame - Home
- Pygame - Overview
- Pygame - Hello World
- Pygame - Display modes
- Pygame - Locals module
- Pygame - Color object
- Pygame - Event objects
- Pygame - Keyboard events
- Pygame - Mouse events
- Pygame - Drawing shapes
- Pygame - Loading image
- Pygame - Displaying Text in Window
- Pygame - Moving an image
- Pygame - Moving with Numeric pad keys
- Pygame - Moving with mouse
- Pygame - Moving Rectangular objects
- Pygame - Use Text as Buttons
- Pygame - Transforming Images
- Pygame - Sound objects
- Pygame - Mixer channels
- Pygame - Playing music
- Pygame - Playing Movie
- Pygame - Using Camera module
- Pygame - Load cursor
- Pygame - Access CDROM
- Pygame - The Sprite Module
- Pygame - PyOpenGL
- Pygame - Errors and Exception
- Pygame Useful Resources
- Pygame - Quick Guide
- Pygame - Useful Resources
- Pygame - Discussion
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Pygame - Playing Movie
Pygame has discontinued support for video files in its latest version. However, earlier versions on Python 2.7 distributions, it can be still used. For this section, Pygame 1.9.2 and Python 2.7.18 has been used.
The pygame.movie module supports playback video and audio from basic encoded MPEG-1 video files. Movie playback happens in background threads, which makes playback easy to manage. the pygame.mixerpygame module for loading and playing sounds module must be uninitialized if the movie’s sound is to be played.
To begin with obtain a Movie object by following syntax −
movie = pygame.movie.Movie('sample.mpg')
The Movie class provides following methods to control playback.
pygame.movie.Movie.play | start playback of a movie |
pygame.movie.Movie.stop | stop movie playback |
pygame.movie.Movie.pause | temporarily stop and resume playback |
pygame.movie.Movie.skip | advance the movie playback position |
pygame.movie.Movie.rewind | restart the movie playback |
pygame.movie.Movie.get_time | get the current vide playback time |
pygame.movie.Movie.get_length | the total length of the movie in seconds |
pygame.movie.Movie.get_size | get the resolution of the video |
pygame.movie.Movie.has_audio | check if the movie file contains audio |
pygame.movie.Movie.set_volume | set the audio playback volume |
pygame.movie.Movie.set_display | set the video target Surface |
Following code plays a .MPG file on the Pygame display window. −
import pygame FPS = 60 pygame.init() clock = pygame.time.Clock() movie = pygame.movie.Movie('sample_640x360.mpg') 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()
Advertisements