2014-12-10 8 views
2

내가 루프 전에 파이썬 스크립트파이 게임 영화는 더

에서 파이 게임 동영상의 사운드에 문제가 재생 다른 모든 시간 나는 그런 식으로 그것을 initalize 소리하지 다음과 같이 재생되는 비디오를 트리거 할 수 있습니다.

pygame.display.init()    
movie = pygame.movie.Movie(path) 
if movie.has_video(): 
    screen = pygame.display.set_mode(movie.get_size()) 
    pygame.display.update() 

    movie.set_display(screen) 
    movie.set_volume(0.99) 

    movie.play() 

    while movie.get_busy(): 
     time.sleep(.100) 

    pygame.display.quit() 

처음으로 영화가 재생되면 소리를들을 수 있습니다. 두 번째로 소리가 나지 않을 때 세 번째 소리는 다시 잘 작동합니다 ... 등등.

pygame.mixer.get_init으로 pygame.display.init을 체크하면 믹서가 초기화되면 false를 반환합니다.

또한 pygame.mixer.quit()을 루프 안에 넣으면 비디오가 실제로 느려지 며 (사운드가없는 경우) 잠시 후 completly 중단됩니다.

+0

왜 당신도 할 것'pygame.mixer.quit()'이후 그 믹서 기능을 제거? _ "pygame.mixer.quit - 믹서를 초기화하지 않음"_ - 또한 파이어 엠. 믹서()를 호출하여 미디어를 재생하기 전에 믹서가로드되었는지 확인하십시오 ? 그런 식으로 믹서를 초기화했으며 일부 희한한 비하인드 마술에 의존하지 않는다는 것을 알고 있습니다. – Torxed

+0

비디오가 사운드를 재생할 수 있도록 믹서를 종료하는 것이 중요합니다. http://www.pygame.org/docs/ref/movie.html – Jodo

+0

이상하게 들리지만 테스트를 거치지 않으면이 사실을 알 수 있습니다. 그렇다면'pygame.mixer.quit()'를 movie.play() 바로 앞에 놓고 해결했는지 확인하십시오. 어쩌면 파이 게임의 초기화 자체가 시간이 걸리고 믹서를 다시 "살아"있게 만드는'display.init()'라고 불렀던 것들을 수행합니다. – Torxed

답변

0

어쩌면 더 대답보다 해결 방법 : 내가 여러 영화를 재생할 때 사운드 재생을 유지하기 pygame.movie있어

유일한 방법은 이것이다 :

  • 내가 처음으로 영화를 만들기 전에, 내가 전화 pygame.mixer.quit()

  • 새 영화를보고 싶을 때마다 movie = pygame.movie.Movie('SOMEOTHERVIDEO.MPG') 번을 두 번 호출합니다.

  • 그 별난,하지만 나를 위해 유일한 방법은 내가 일하고있어. 이것은 win7/python3에 있습니다

  • 나는 pygame.movie.Movie('SOMENEWVIDEO.MPG')에 대한 2 건 중 첫 번째 호출에서 movie=을 제거하면이 해결 방법이 작동하지 않는 것이 이상하게 느껴집니다. 어쨌든 여기

나를 위해 작동하는 일부 코드입니다 :

import pygame 

FPS = 60 

pygame.init() 
clock = pygame.time.Clock() 
pygame.mixer.quit() 
movie = pygame.movie.Movie('SOMEVIDEO.mpg') 
screen = pygame.display.set_mode(movie.get_size()) 
movie_screen = pygame.Surface(movie.get_size()).convert() 

movie.set_display(movie_screen) 
movie.play() 

cnt = 0 
playing = True 
while playing: 
    cnt+=1 
    if cnt>=500: 
     cnt=0 
     movie.stop() 
     movie = pygame.movie.Movie('SOMEOTHERVIDEO.mpg') 
     movie = pygame.movie.Movie('SOMEOTHERVIDEO.mpg') 
     movie_screen = pygame.Surface(movie.get_size()).convert() 
     movie.set_display(movie_screen) 
     movie.play() 
    for event in pygame.event.get(): 
     if event.type == pygame.QUIT: 
      movie.stop() 
      playing = False 
    screen.blit(movie_screen,(0,0)) 
    pygame.display.update() 
    clock.tick(FPS) 

pygame.quit()