I don't know if this is a universal problem, but if I simply do
pyglet.media.play(somesource) several times, my macbook air almost
dies from performance issues.

So here's what I did to solve this (maybe that seems stupid, no idea,
maybe it's useful for others)

from pyglet import media

class Player(object):
    def __init__(self, free, busy):
        self.free = free
        self.busy = busy
        self.player = media.Player()
        self.player.push_handlers(self)

    def play(self, source):
        self.player.queue(source)
        if self.player.playing:
            self.player.next()
        else:
            self.player.play()

    def on_eos(self):
        self.busy.remove(self)
        self.free.insert(0, self)

class Channel(object):
    def __init__(self, amount=6):
        self.free = []
        self.busy = []
        for _ in range(amount):
            self.free.append(
                Player(self.free, self.busy)
            )

    def play(self, source):
        if self.free:
            player = self.free.pop()
        else:
            player = self.busy.pop()
        self.busy.insert(0, player)
        player.play(source)

--

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


Reply via email to