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() # initialize GUI movie, playImageSize = createGUI( file ) # wait until player wants to close program while 1: event = pygame.event.wait() # 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() # button pressed if pressed: if playImageSize.collidepoint( position ): movie.play()
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() # initialize GUI movie, playImageSize = createGUI(file) # wait until player wants to close program while 1: event = pygame.event.wait() # 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() # button pressed if pressed: if playImageSize.collidepoint(position): movie.play()
def main(filepath): pygame.init() pygame.mixer.quit() pygame.display.init() movie = pygame.movie.Movie(filepath) w, h = movie.get_size() #print w, h #w = int(w * 1.3 + 0.5) #h = int(h * 1.3 + 0.5) wsize = (w+10, h+10) msize = (w, h) screen = pygame.display.set_mode(wsize) movie.set_display(screen, Rect((5, 5), msize)) pygame.event.set_allowed((QUIT, KEYDOWN)) pygame.time.set_timer(USEREVENT, 1000) movie.play() while movie.get_busy(): pygame.event.wait() if movie.get_busy(): movie.stop() pygame.time.set_timer(USEREVENT, 0)
def load_movie(screen, movie_file, *options): vol = 0.5 # volume starting half way. min is 0.0 max is 1.0 paused = 0 skipped = 0 image = pygame.image.load(gl.MOVIE_FILE).convert() paint_screen(screen, gl.BLACK) pygame.mixer.quit() # so sound in the movie works print movie_file# set_caption("imgv - %s" % movie_file)# movie = pygame.movie.Movie(movie_file) screen_center = ((screen.get_width() / 2) - (movie.get_size()[0] / 2), ((screen.get_height() / 2)) -\ (movie.get_size()[1] / 2)) # where to center the movie if len(options) > 0: if options[0] == "fitwindow": movie.set_display(screen, (0, 0, screen.get_width(), screen.get_height())) else: movie.set_display(screen, screen_center) if len(movie_file) > 70: movie_name = movie_file[:70] + '...' else: movie_name = movie_file movie.play() movie.set_volume(vol) normal_cursor() mute_rect = show_message(screen, "Mute", (20, 0), 12) lower_rect = show_message(screen, "Lower", (80, 0), 12) louder_rect = show_message(screen, "Louder", (140, 0), 12) pause_rect = show_message(screen, "Pause", (200, 0), 12) stop_rect = show_message(screen, "Stop", (260, 0), 12) skip_rect = show_message(screen, "Skip-Half", (320, 0), 12) fw_rect = show_message(screen, "Fit-Window", (400, 0), 12) show_message(screen, "(%d:%02.f)" % (movie.get_length() / 60, movie.get_length() % 60), (480, 0), 12) if gl.TOGGLE_STATUS_BAR: show_message(screen, "%s/%s, %s" % (gl.files.index(movie_file) + 1, len(gl.files),\ os.path.basename(movie_name)), "bottom", 12) flip()# while movie: if not movie.get_busy() and not paused and gl.SLIDE_SHOW_RUNNING: break for event in pygame.event.get(): cursor = pygame.mouse.get_pos() if event.type == KEYDOWN and event.key == K_q or event.type == QUIT: wait_cursor() movie.stop() movie = None clean_screen() raise SystemExit if event.type == KEYDOWN and event.key not in (K_LALT, K_RALT, K_LCTRL, K_RCTRL, K_p, K_TAB): movie.stop() movie = None return image if left_click(event): if mute_rect.collidepoint(cursor): movie.set_volume(0) break if lower_rect.collidepoint(cursor): if vol >= 0.0: vol = vol - 0.2 movie.set_volume(vol) break if louder_rect.collidepoint(cursor): if vol <= 1.0: vol = vol + 0.2 movie.set_volume(vol) break if pause_rect.collidepoint(cursor): if paused: paused = 0 else: paused = 1 movie.pause() break if stop_rect.collidepoint(cursor): movie.stop() movie = None return image if skip_rect.collidepoint(cursor): if not skipped: movie.skip(movie.get_length() / 2) break if fw_rect.collidepoint(cursor): movie.stop() movie = None image = load_movie(screen, movie_file, "fitwindow") break movie = None return image
texture_object = stimulus.parameters.texture.get_texture_object() def update_movie(): # While movie.play() decompresses the movie to pygame surface # in a separate thread, this sends the data to OpenGL. texture_object.put_sub_image(pygame_surface) viewport = Viewport(screen=screen, stimuli=[stimulus, text]) p = Presentation( go_duration=('forever', ), viewports=[viewport], handle_event_callbacks=[(pygame.locals.QUIT, quit), (pygame.locals.KEYDOWN, keydown)], ) p.add_controller( None, None, FunctionController(during_go_func=update_movie, temporal_variables=TIME_INDEPENDENT)) movie.play() #p.go() import cProfile, pstats cProfile.run('p.go()', 'mpeg_profile') p = pstats.Stats('mpeg_profile') p.sort_stats('cumulative') p.print_stats()
anchor = 'center', size = (width*scale,height*scale), mipmaps_enabled = 0, texture_min_filter=gl.GL_LINEAR) texture_object = stimulus.parameters.texture.get_texture_object() def update_movie(): # While movie.play() decompresses the movie to pygame surface # in a separate thread, this sends the data to OpenGL. texture_object.put_sub_image( pygame_surface ) viewport = Viewport(screen=screen, stimuli=[stimulus,text]) p = Presentation(go_duration=('forever',), viewports=[viewport], handle_event_callbacks=[(pygame.locals.QUIT, quit), (pygame.locals.KEYDOWN, keydown)], ) p.add_controller(None,None,FunctionController(during_go_func=update_movie, temporal_variables=TIME_INDEPENDENT)) movie.play() #p.go() import cProfile,pstats cProfile.run('p.go()','mpeg_profile') p = pstats.Stats('mpeg_profile') p.sort_stats('cumulative') p.print_stats()