Pyglet stops playing sounds after being called multiple times

499 views
Skip to first unread message

John Bent

unread,
Apr 22, 2015, 5:08:52 PM4/22/15
to pyglet...@googlegroups.com
I have a large number of small mp3 files that I need to check individually. In a python foreach file loop, I'm calling this function which uses pyglet:

def play(player,src):
 
try:
   
#music = pyglet.resource.media(src)
    music
= pyglet.media.load(src, streaming=False)
    music
.play()
    ans
= raw_input("\tWas this sound good (r to replay, q to quit)? [y|n|r|q]: ")
   
if (ans == 'r'):
     
return play(player,src)
   
if (ans == 'q'):
      sys
.exit(0)
   
else:
      success
= (ans == 'y')
 
except pyglet.media.avbin.AVbinException, e:
   
print "Exception playing file. Assuming bad."
    success
= 0  
 
print "%s -> %d" % ( src, success )
 
return success

It works great for about 10 files but then it just stops working without any error indication that I'm noticing. It acts like it is playing the sounds but there is just silence. Is there some resource I should be unloading or deallocating or something? I'm on OS X and initially had to install AVBin to get pyglet to work at all.

Thanks!

Ricky Ng

unread,
Apr 22, 2015, 5:18:38 PM4/22/15
to pyglet...@googlegroups.com
I'm going to take a guess and say that decoding 10 files
simultaneously may be causing the issue.

If you are loading a bunch of shorter sounds, maybe try using
StaticSource instead?
> --
> 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 pyglet-users...@googlegroups.com.
> To post to this group, send email to pyglet...@googlegroups.com.
> Visit this group at http://groups.google.com/group/pyglet-users.
> For more options, visit https://groups.google.com/d/optout.



--
Incoherently,
Ricky Ng

John Bent

unread,
Apr 22, 2015, 5:27:50 PM4/22/15
to pyglet...@googlegroups.com
Thanks!

However, I don't think I'm loading them simultaneously since it plays one and then waits for user input to verify that it is good audio.

I'll try static source.
> You received this message because you are subscribed to a topic in the Google Groups "pyglet-users" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/topic/pyglet-users/h8pBM1EPVa8/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to pyglet-users...@googlegroups.com.

John Bent

unread,
Apr 22, 2015, 6:11:18 PM4/22/15
to pyglet...@googlegroups.com
Staticsource didn't solve the problem.  I replaced

> pyglet.media.load(src, streaming=False)
with
> pyglet.media.StaticSource(pyglet.media.load(src))

But it still behaves the same.

Thanks,

John

Adam Bark

unread,
Apr 22, 2015, 6:31:45 PM4/22/15
to pyglet...@googlegroups.com
Hmm, do you get the same problem with uncompressed audio, i.e. can you test with some wavs please?

John Bent

unread,
Apr 23, 2015, 12:17:03 PM4/23/15
to pyglet...@googlegroups.com
Thanks Adam for the suggestion.  Unfortunately the problem is the same with wavs that I created by converting the mp3s into wavs with sox.  Here's what the wavs look like:

Input File     : '426.wav'

Channels       : 1

Sample Rate    : 22050

Precision      : 16-bit

Duration       : 00:00:02.51 = 55296 samples ~ 188.082 CDDA sectors

File Size      : 111k

Bit Rate       : 353k

Sample Encoding: 16-bit Signed Integer PCM

John Bent

unread,
Apr 23, 2015, 4:07:44 PM4/23/15
to pyglet...@googlegroups.com
If I completely quit the program and rerun it, it works again for about another 10.  But I'd rather not do this because the program does some other slow initialization work and I'd rather not wait every time for that.

So isn't there some way I can effectively "quit" the pyglet stuff and rerun it within the python program that would have the same effect as fulling quitting the entire python program?

--

Ricky Ng

unread,
Apr 23, 2015, 4:10:33 PM4/23/15
to pyglet...@googlegroups.com
The spec here: http://pyglet.org/doc-current/api/pyglet/pyglet.media.html

Says you can force a garbage collection. Your problem may be that you
have too many players at the same time (I honestly have never had this
problem ), so maybe cleaning them up will work.
> 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 pyglet-users...@googlegroups.com.
> To post to this group, send email to pyglet...@googlegroups.com.
> Visit this group at http://groups.google.com/group/pyglet-users.
> For more options, visit https://groups.google.com/d/optout.



--
Incoherently,
Ricky Ng

John Bent

unread,
Apr 23, 2015, 4:16:31 PM4/23/15
to pyglet...@googlegroups.com
Thanks Ricky!  But it didn't work.  I added the gc.collect() and I thought maybe it did more work before failing but it still ultimately failed.  Oh, well, I'm checking a finite number of mp3's only so I can live with this bug.

Adam Bark

unread,
Apr 23, 2015, 6:05:08 PM4/23/15
to pyglet...@googlegroups.com
At the risk of grasping at straws, what if you instantiate your own player and add your sources to that rather than using the implicit creation in .play()?

Rob

unread,
Apr 24, 2015, 3:10:35 PM4/24/15
to pyglet...@googlegroups.com
For 1.3.x I am in the process of fully testing and refactoring the media package. I noticed quite some possible issues, so I am going to add this to the test suite to verify.

At the moment I have only been stressing PulseAudio, as OpenAL (which we use on OSX) was having issues on my machine. I just upgraded to Kubuntu 15.04, so maybe OpenAL now works for me. I also still need to do Windows/DirectSound.

Rob

Op vrijdag 24 april 2015 00:05:08 UTC+2 schreef Adam:

Florian Höch

unread,
Apr 26, 2015, 9:24:40 AM4/26/15
to pyglet...@googlegroups.com
I ran into a similar sounding (pun not intended) problem. What seems to work is keeping a reference to the player instance returned by play() (or instantiating your own player) and explicitly calling delete() on it when done with it.
Reply all
Reply to author
Forward
0 new messages