Modify fig24_06.py so that a user can play, stop, pause and rewind a movie.

What will be an ideal response?


```
# Simple movie player using pygame.

import os
import sys
import pygame, pygame.movie, pygame.font
import pygame.mouse, pygame.image
from pygame.locals import *

def createGUI( file ):

# define global values
global movie, screen, width, height, playImageSize
global stopImageSize, pauseImageSize, rewindImageSize

# load movie
movie = pygame.movie.Movie( file )
width, height = movie.get_size()

# initialize display window
screen = pygame.display.set_mode( ( width, height + 100 ) )
pygame.display.set_caption( "Movie Player" )
pygame.mouse.set_visible( 1 )

# play button
playImageFile = os.path.join( "data", "play.png" )
playImage, playImageSize = addButton( playImageFile, 50 )

# stop button
stopImageFile = os.path.join( "data", "stop.png" )
stopImage, stopImageSize = addButton( stopImageFile, 130 )

# pause button
pauseImageFile = os.path.join( "data", "pause.png" )
pauseImage, pauseImageSize = addButton( pauseImageFile, 210 )

# rewind button
rewindImageFile = os.path.join( "data", "rwd.png" )
rewindImage, rewindImageSize = addButton(
rewindImageFile, 290 )

# copy play button to screen
screen.blit( playImage, playImageSize )
screen.blit( stopImage, stopImageSize )
screen.blit( pauseImage, pauseImageSize )
screen.blit( rewindImage, rewindImageSize )
pygame.display.flip()

# set output surface for the movie's video
movie.set_display( screen )

def addButton( imageFile, centerX ):
buttonImage = pygame.image.load( imageFile ).convert()
buttonImage.set_colorkey( buttonImage.get_at( ( 0, 0 ) ) )
buttonImageSize = buttonImage.get_rect()
buttonImageSize.centerx = centerX
buttonImageSize.centery = height + 50

return buttonImage, buttonImageSize

def main():

# check command line arguments
if len( sys.argv ) != 2:
sys.exit( "Incorrect number of arguments." )
else:
file = sys.argv[ 1 ]

# initialize pygame
pygame.init()

# create GUI
createGUI( file )

# wait until player wants to close program
while 1:
event = pygame.event.poll()

# close window
if event.type == QUIT or \
( event.type == KEYDOWN and event.key == K_ESCAPE ):
break

# click play button and play movie
pressed = pygame.mouse.get_pressed()[ 0 ]
position = pygame.mouse.get_pos()

if pressed:

if playImageSize.collidepoint( position ):
movie.play()

elif stopImageSize.collidepoint( position ):
movie.stop()
movie.rewind()

elif pauseImageSize.collidepoint( position ):
movie.pause()

elif rewindImageSize.collidepoint( position ):
movie.rewind()
screen.fill(
( 250, 250, 250 ), ( 0, 0, width, height ) )
pygame.display.flip()

if __name__ == "__main__":
main()
```
![15199|243x239](upload://smEtN6fdiOZukowcggbl11gAskY.png)

Computer Science & Information Technology

You might also like to view...

Assume that i = 1, j = 2, k = 3 and m = 2. What does each of the following statements print?

``` a) System.out.println(i == 1); b) System.out.println(j == 3); c) System.out.println((i >= 1) && (j < 4)); d) System.out.println((m <= 99) & (k < m)); e) System.out.println((j >= i) || (k == m)); f) System.out.println((k + m < j) | (3 - j >= k)); g) System.out.println(!(k > m)); ```

Computer Science & Information Technology

Malicious tampering occurring internally by a disgruntled employee can subtly alter data that may not be noticed for some time after the employee leaves the company

Indicate whether the statement is true or false

Computer Science & Information Technology

The last step in planning a Windows Form application is to ____.

A. draw a sketch of the user interface B. identify the objects to which tasks will be assigned C. identify the tasks the application needs to perform D. identify the event required to trigger an object to perform its assigned tasks

Computer Science & Information Technology

C provides two functions to build a random number series.

Answer the following statement true (T) or false (F)

Computer Science & Information Technology