Re: the looping question -- to make a sound play in a loop, you can use a 
Player:

# create a player and queue the song
> player = pyglet.media.Player()
> sound = pyglet.media.load('lines.mp3')
> player.queue(sound) 

 

# keep playing for as long as the app is running (or you tell it to stop):
> player.eos_action = pyglet.media.Player.EOS_LOOP 

 

player.play()


To play more background sounds simultaneously, just start up another player 
for each of the sounds, with the same EOS_LOOP "eos_action" setting as 
above for each of them.

About why your code doesn't continue to execute after calling 
pyglet.app.run()  -- pyglet.app.run() should be the last thing you call 
after setting up everything else needed for your app (the events, graphics 
to draw, etc.), because it starts an event loop.  There's a good 
explanation of this 
here: 
http://www.pyglet.org/doc/programming_guide/calling_functions_periodically.html 
.


On Tuesday, April 2, 2013 5:30:01 PM UTC-4, Itzik Hanoch wrote:
>
> Thanks for your answer,
> But now i get:
>
> TypeError: exit() takes no arguments (1 given)
>
> And i have no idea why.
>
> Plus, Is there a way to just let the sound play and continue on without 
> waiting?
> Because now i am still waiting for it to end which is bad...
>
> On Tuesday, April 2, 2013 10:25:50 AM UTC+3, Pranav Ravichandran wrote:
>>
>> You need to use the clock.schedule_once() method if I remember right.
>>
>> stream = pyglet.resource.media(mediaFile)
>> stream.play()
>> pyglet.clock.schedule_once(pyglet.app.exit, stream.duration)
>> pyglet.app.run() 
>>
>>
>>
>> On Tue, Apr 2, 2013 at 3:57 AM, Itzik Hanoch <[email protected]> wrote:
>>
>>> Hi guys,
>>>
>>> Im new to pyglet (so far it looks like a great library) and im trying to 
>>> do the following:
>>>
>>> 1)Have a background music which will play (unless stopped somewhere in 
>>> the code)
>>>
>>> 2)Ability to add  more sounds over this background music
>>>
>>> 3)Ability to add more background sounds that will continue to play always
>>>
>>> this is what i have so far (Very simple):
>>>
>>> *def parse(fd):*
>>>
>>> *    for line in fd:*
>>>
>>> *        for word in line.split():*
>>>
>>> *            if(word == "word"):*
>>>
>>> *                s1 = pyglet.resource.media("lines.mp3");*
>>>
>>> *                s1.play()*
>>>
>>> *                s2 = pyglet.resource.media("look.mp3")*
>>>
>>> *                s2.play()*
>>>
>>> *                pyglet.app.run()       <-----Cant get pass this*
>>>
>>> *
>>> *
>>>
>>> *def filehandle(filename):*
>>>
>>> *    while(True):*
>>>
>>> *        print "parsing"*
>>>
>>> *        fd = open(filename,'r+')*
>>>
>>> *        parse(fd)*
>>>
>>> *        fd.close()*
>>>
>>> *
>>> *
>>>
>>> *if __name__ == '__main__':*
>>>
>>> *    print "Please enter file name: ";  *
>>>
>>> *    filename = raw_input()*
>>>
>>> *    filehandle(filename)*
>>>
>>> *    sys.exit()*
>>>
>>> The thing is, as mentioned, i cant get pass the *pyglet.app.run() *since 
>>> it will wait for the song to end and then perform another loop iteration.
>>>
>>> (never mind i am always adding the same sounds, i just want to learn how 
>>> this can be done)
>>>
>>> How could this be done?
>>>
>>> Thanks!
>>>
>>>
>>>  -- 
>>> You received this message because you are subscribed to the Google 
>>> Groups "pyglet-users" group.
>>> To unsubscribe from this group and stop receiving emails from it, send 
>>> an email to [email protected].
>>> To post to this group, send email to [email protected].
>>> Visit this group at http://groups.google.com/group/pyglet-users?hl=en.
>>> For more options, visit https://groups.google.com/groups/opt_out.
>>>  
>>>  
>>>
>>
>>
>>
>> -- 
>> E-ThoughtDumpyard <http://www.onloop.net/>
>>  
>

-- 
You received this message because you are subscribed to the Google Groups 
"pyglet-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/pyglet-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to