I tried to put app.run() into its own thread. But it fails:
from threading import Thread
import pyglet
class SoundThread(Thread):
def __init__(self, pyglet):
Thread.__init__(self)
self.pyglet = pyglet
def run(self):
self.pyglet.app.run()
sthread = SoundThread(pyglet)
sthread.start()
def play_sound():
path = "test.wav"
source = pyglet.media.load(path, streaming=False)
player.queue(source)
If I call play_sound() it will play the sound once. Then, after it ended,
following error occurs:
ArgumentError: argument 2: <type 'exceptions.TypeError'>: expected
CFunctionType instance instead of NoneType
In the self.pyglet.app.run()inside the thread.
I also make some tests with the code before adding the Thread and it seems
that the first sound is played and the queque does not jump to the next if
one is added to the queue. Reading player.source and player.time, after the
sound is played one time, says: source last played source, time is the
length of the audiofile. But it does not use the next source. I tried
player.next_source();
player.play() if source is not None before adding to queue, but it makes no
difference.
/Sebastian
Am Dienstag, 17. Februar 2015 22:52:52 UTC+1 schrieb Sebastian Meyer:
>
> No. For testing I loaded all Sounds as pyglet.media.StaticSound into a
> dict and call it from there. Same there: only the first sound works.
> Maybe the missing pyglet-loop because I don't run pyglet.app.run() ?
>
> Am Dienstag, 17. Februar 2015 22:40:46 UTC+1 schrieb Richard Jones:
>>
>> Does pre-loading all the sounds make a difference?
>>
>> On Wed Feb 18 2015 at 8:21:19 AM Sebastian Meyer <
>> [email protected]> wrote:
>>
>>> Hmm, ok that sounds possible.
>>> I tried this:
>>>
>>> player = pyglet.media.Player() # init player
>>> player.play() # let player play
>>>
>>> def play_sound(name):
>>> path = name + ".wav"
>>> source = pyglet.media.load(path, streaming=False)
>>> print "Playing sound!", name
>>> player.queue(source)
>>>
>>>
>>> This works for exactly one sound. The second call of the function brings
>>> the print-statement but no sound.
>>> Did I missunderstand something?
>>> I tried also a player.play() after adding the source to the queue - same
>>> result.
>>>
>>> Thanks,
>>> Sebastian
>>>
>>>
>>> Am Dienstag, 17. Februar 2015 17:05:43 UTC+1 schrieb Rob:
>>>
>>>> I suspect a new player is created for every sound. The player registers
>>>> a stream. As long as the player is not destroyed, the stream remains
>>>> active. Try if you can control a single player: http://pyglet.
>>>> readthedocs.org/en/pyglet-1.2-maintenance/programming_guide/media.html
>>>>
>>>> Rob
>>>>
>>>> Op dinsdag 17 februari 2015 11:36:41 UTC+1 schreef Sebastian Meyer:
>>>>>
>>>>> Hi there!
>>>>>
>>>>> I have a small project which uses pyQt for the GUI. It is
>>>>> OS-independent and I want to add some sound-notifacation on it.
>>>>> After some searching I decided the best solution to have
>>>>> OS-independent sound-output is using pyglet for it. And it works great.
>>>>>
>>>>> But there is one problem:
>>>>> I'm using Linux with KDE and the mixer for adjusting the volume-level
>>>>> shows a modulator for every program that plays sound.
>>>>> But for my programm it shows a new regulator everytime I use pyglet to
>>>>> play a sound. So after the first sound, there appears one, after the
>>>>> second
>>>>> there are two and so on.
>>>>>
>>>>> I'm playing the sound as descripted here:
>>>>> http://www.pyglet.org/doc/programming_guide/playing_
>>>>> sounds_and_music.html
>>>>>
>>>>> Any ideas?
>>>>>
>>>>> Cheers
>>>>> Sebastian
>>>>>
>>>> --
>>> 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.
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
--
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.
For more options, visit https://groups.google.com/d/optout.