[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[pygame] threads with mplayer



I'm looking into making a car app with pygame. I have it playing mp3's and
mpegs just fine. I'd like to use mplayer for at least the video though. I
have never worked with threads so don't flame me if this is the wrong way
to go about this. I'd like to have a movie running in fullscreen mode but
still have all the events going through python. Right now if my mouse is
over the mplayer window mplayer takes all the events. I'm wondering if
this is possible. Do I have to subclass threading or thread for this to
work?

Here is just some sample code of me getting mplayer working in a thread

import pygame
from pygame.locals import *
import thread
from time import sleep, time, ctime
import os
import sys

mplayer_loc = '/usr/local/bin/mplayer'
mplayer_args = ' -vo xv -slave '
file = '/dump/mp3s/1short.mpeg'

def loop0():
        print "using mplayer which is at: ", mplayer_loc
        os.system(mplayer_loc + mplayer_args + file)
        while 1:
                for event in pygame.event.get():
                        if event.type == KEYDOWN:
                                 print "KeyDown on the MOVIE!",
event.key

def main():
        pygame.init()
        window = pygame.display.set_mode((600,400))
        pygame.display.set_caption('testing')
        #pygame.display.toggle_fullscreen()
        print 'starting threads'
        thread.start_new_thread(loop0, ())
        while 1:
                for event in pygame.event.get():
                        if event.type == KEYDOWN:
                                print "KeyDown", event.key
        print 'all done at: ', ctime(time())


if __name__ == '__main__':
        main()