Pygame Tutorial
Selected Reading
- Pygame - Discussion
- Pygame - Useful Resources
- Pygame - Quick Guide
- Pygame - Errors and Exception
- Pygame - PyOpenGL
- Pygame - The Sprite Module
- Pygame - Access CDROM
- Pygame - Load cursor
- Pygame - Using Camera module
- Pygame - Playing Movie
- Pygame - Playing music
- Pygame - Mixer channels
- Pygame - Sound objects
- Pygame - Transforming Images
- Pygame - Use Text as Buttons
- Pygame - Moving Rectangular objects
- Pygame - Moving with mouse
- Pygame - Moving with Numeric pad keys
- Pygame - Moving an image
- Pygame - Displaying Text in Window
- Pygame - Loading image
- Pygame - Drawing shapes
- Pygame - Mouse events
- Pygame - Keyboard events
- Pygame - Event objects
- Pygame - Color object
- Pygame - Locals module
- Pygame - Display modes
- Pygame - Hello World
- Pygame - Overview
- Pygame - Home
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
Pygame - Playing Movie
Pygame - Playing Movie
Pygame has discontinued support for video files in its latest version. However, earper 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 uninitiapzed 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.bpt(movie_screen,(0,0)) pygame.display.update() clock.tick(FPS) pygame.quit()Advertisements