×

Discussion Board

Results 1 to 4 of 4
  1. #1
    Registered User
    Join Date
    Nov 2009
    Posts
    4

    Unhappy playing a wav file in a separate thread

    Hey,

    Based on the example given in the "Mobile Python" book (simply amazing book btw), i've managed to get my application to open and play a .wav file until it finishes, by using the sound callback function. What I'm trying to do now is initiate the act of playing the sound inside a NEW thread, so my main thread can continue its execution without being held by the Ao_lock(). This is what I've done so far, I try opening the audio file and then pass the open handler to a new thread, and I've included the sound_callback function as a nested function inside my threaded one, so that it has access to the sound_lock object (no race condition, i hope!). But, it doesn't seem to get past the "here in the beginning" point... does anyone have an idea what might be going wrong?

    Thnx in advance!!

    Code:
    def sound_thread(sound):
    
    	sound_lock = e32.Ao_lock()
    
    	def sound_callback(prev_state, current_state, err):
    		print "here in the middle"
    		if current_state == audio.EOpen:
    			sound_lock.signal()
    	
    	print "here at the beginning"
    	sound.play(callback = sound_callback)
    	sound_lock.wait()
    	sound.close()
    	print "here at the end"
    
    def playsound(file_name):
    
    	sound_file = SOUNDS_PATH + file_name + ".wav"
    	sound = audio.Sound.open(sound_file)
    	
    	thread.start_new_thread(sound_thread, (sound, ))

  2. #2
    Super Contributor
    Join Date
    Nov 2007
    Location
    Sertaozinho/Brazil
    Posts
    768

    Re: playing a wav file in a separate thread

    Hi trellos

    My tests trying to play a sound from threads failed. I could not find in docs anything saying that this is forbidden but I did not listen any sound, just some glitches.

    Code:
    from threading import Thread
    import audio
    import time
    
    def tocar(musica):
        m = audio.Sound.open(musica)
        m.play()
    
    t1 = Thread(target=tocar,args=(u'e:\\Music\\Cake\\Prolonging The Magic\\03 Never There.mp3',))
    t2 = Thread(target=tocar,args=(u'e:\\Music\\Cake\\Prolonging The Magic\\04 Guitar.mp3',))
    
    t1.start()
    
    print "1"
    
    time.sleep(15)
    
    print "2"
    
    t2.start()

  3. #3
    Registered User
    Join Date
    Nov 2009
    Posts
    4

    Re: playing a wav file in a separate thread

    Hey thanks for the reply, that's my problem as well, no sound gets played! I initially thought that the sound file could not be opened in a thread (i got a kerror -4 not enough memory, if I remember correctly), that's why I opened the file inside the main thread and then passed the file handler into the (new) thread. I'm guessing the problem lies with the Ao_lock executing from within the new thread itself, it doesn't seem to work as it's supposed to..

    Quote Originally Posted by marcelobarrosalmeida View Post
    Hi trellos

    My tests trying to play a sound from threads failed. I could not find in docs anything saying that this is forbidden but I did not listen any sound, just some glitches.

    Code:
    from threading import Thread
    import audio
    import time
    
    def tocar(musica):
        m = audio.Sound.open(musica)
        m.play()
    
    t1 = Thread(target=tocar,args=(u'e:\\Music\\Cake\\Prolonging The Magic\\03 Never There.mp3',))
    t2 = Thread(target=tocar,args=(u'e:\\Music\\Cake\\Prolonging The Magic\\04 Guitar.mp3',))
    
    t1.start()
    
    print "1"
    
    time.sleep(15)
    
    print "2"
    
    t2.start()

  4. #4
    Registered User
    Join Date
    Nov 2009
    Posts
    4

    Re: playing a wav file in a separate thread

    So there's no way to get the sound file to start playing inside a new thread?? is it a limitation of the phone?

Similar Threads

  1. [moved] Cannot run the S60 5th ed Emulator (tagma.dll assertion)
    By Carbider in forum Symbian Tools & SDKs
    Replies: 20
    Last Post: 2010-06-07, 17:21
  2. [moved] Theme Studio Error
    By TalJ in forum Themes/Carbide.ui
    Replies: 2
    Last Post: 2009-09-06, 03:39
  3. console app running problem
    By xcompass in forum Symbian C++
    Replies: 3
    Last Post: 2009-05-08, 13:26
  4. Problem with pyobfuscate
    By JOM in forum Python
    Replies: 3
    Last Post: 2008-06-20, 22:47
  5. Replies: 1
    Last Post: 2005-05-26, 14:22

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •