[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [pygame] diff betn interactive and non-interactive scripts



On Wed, 2002-04-10 at 02:27, Prahlad Vaidyanathan wrote:
> 
> Hi,
> 
> On Wed, 10 Apr 2002 Richard Jones spewed into the ether:
> [-- snippity --]
> > try putting a "while 1: pass" or "time.sleep(100)" at the end of the script - 
> > it looks to my eye (which is almost totally ignorant of how all this works, 
> > so is just guessing ;) like the program is exiting before the mixer can 
> > actually play anything...
> 
> Amazingly, that works !
> 
> I basically now check the total time of the song, and then put in a
> time.sleep() for that long.
> 
> This is *seriously* weird from where I stand. Could someone explain why
> this happens ?

The function returns immediately because most of the time a game or some
such other multimedia program would want to do other processing (like
drawing graphics and taking input) while the music is playing. If there
were only a blocking interface, you'd have to use a thread just to play
music, which would be silly.

Anyway, a better solution than one big time.sleep() would probably be to
continuously poll if the music is done playing or not, every few
seconds. I'm not sure if there is a poll function (although i'm betting
there is), but if there were, your code would be something like:

while music_still_playing():
    time.sleep(5)

-- 
                                Chris Armstrong
                         << radix@twistedmatrix.com >>
                http://twistedmatrix.com/users/carmstro.twistd/

____________________________________
pygame mailing list
pygame-users@seul.org
http://pygame.seul.org