thanks for the example!
gracias por el ejemplo!

Jose Luis DALLAPICCOLA escribió:
Hello. Sorry, i'm not speak english.
Te adjunto al presente correo una porción de código que he escrito
para otra aplicación.
Lo que hace es reproducir un vídeo en forma contínua.
Cuando detecta la tecla ESPACIO comienza desde el principio; cuando
detecta la tecla ESCAPE detiene la ejecución del vídeo.
Espero que te sirva.
Saludos a todos,

2006/10/7, altern <[EMAIL PROTECTED]>:
hi

anyone has an example to share of the use of
pygame.movie.Movie commands to play video?

thanks

enrike




------------------------------------------------------------------------

#!/usr/bin/python
# -*- coding: utf-8 -*-

import os
import pygame
from pygame.locals import *

SCREEN_WIDTH = 800
SCREEN_HEIGHT = 600
#SCREEN_OPTIONS = FULLSCREEN
SCREEN_OPTIONS = 0
DATA = '.'

def load_image(name, colorkey = None):
        fullname = os.path.join(DATA, name)
        try:
                image = pygame.image.load(fullname)
        except pygame.error, message:
                print 'No se puede cargar la imagen: ', fullname
                raise SystemExit, message
        
        image = image.convert()
        if colorkey:
                colorkey = image.get_at((0, 0))
                image.set_colorkey(colorkey, RLEACCEL)
        
        return image, image.get_rect()

def load_sound(name):
        class NoSound:
                def play(self):
                        pass
                def stop(self):
                        pass
                def get_length(self):
                        return 0
        
        if not pygame.mixer or not pygame.mixer.get_init():
                sound = NoSound()
        else:
                fullname = os.path.join(DATA, name)
                
                if os.path.exists(fullname):
                        sound = pygame.mixer.Sound(fullname)
                else:
                        print 'No se puede cargar el sonido: ', fullname
                        sound = NoSound()
        
        return sound

def load_movie(name):
        fullname = os.path.join(DATA, name)
        try:
                movie = pygame.movie.Movie(fullname)
        except pygame.error, message:
                print 'No se puede cargar el vídeo: ', fullname
                raise SystemExit, message
        
        return movie

def publicidad_show(screen):
        continuar = True
        
        pygame.mixer.quit()
        movie = load_movie('mo.mpg')
        movie.set_display(screen, screen.get_rect())
        
        movie.play(0)

        pygame.time.delay(500)                                  # Para evitar 
una repetición de tecla no deseada
        while continuar:
                if not movie.get_busy():
                        movie.rewind()
                        movie.play(0)
                
                pygame.event.pump()
                keyinput = pygame.key.get_pressed()
                if keyinput[K_SPACE]:
                        continuar = False
                elif keyinput[K_ESCAPE]:
                        raise SystemExit
        
        movie.stop()
        pygame.init()

def main():
        pygame.init()
        pygame.key.set_repeat()
        
        screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT), 
SCREEN_OPTIONS)
        pygame.display.set_caption('Ejemplo')
        pygame.mouse.set_visible(False)
        
        while True:
                publicidad_show(screen)

if __name__ == '__main__':
        main()

Reply via email to