×

Discussion Board

Results 1 to 7 of 7
  1. #1
    Registered User
    Join Date
    Mar 2006
    Posts
    29

    [solved]how to check if an audio file has stopped playing ?

    Hello,

    I am still exploring the possibilities of pys60, and now I'm trying to write a simple shoutcast client.
    The audio module doesn't seem to handle streams, so I have to write down the stream to two files: one is played while the other records the current stream, and so on.
    I need to find out when the playing of the file is over ( that's when I am switching the recording file with the playing file), so I am experimenting a bit with the code in order to understand better the logic of the module ...

    Here, I am testing if the Sound.state function can do that:
    Code:
    import audio
    son = audio.Sound.open('E:\\Others\\buff2.mp3')
    son.play()
    i = 1
    while son.state() == 2 and i < 2000:
        print i
        i = i+1
    buff2.mp3 is 5 seconds long.
    This piece of code should be ending well before i reaches 2000, and this is not the case.
    Anyone sees what's wrong in there ?

    (after a quick check state() returns an integer. 2 is equivalent to audio.EPlaying)
    Last edited by MrKikkeli; 2006-03-20 at 17:31. Reason: problem solved.

  2. #2
    Super Contributor
    Join Date
    Dec 2004
    Posts
    643

    Re: how to check if an audio file has stopped playing ?

    I didn't write the audio module, but I'm guessing that busy wait loop you have there doesn't give the audio object the opportunity to update its state. Try inserting e32.ao_yield() in the loop. That will run the active scheduler and process pending events.

  3. #3
    Registered User
    Join Date
    Feb 2005
    Location
    Belgium (Europe)
    Posts
    1,352

    Re: how to check if an audio file has stopped playing ?

    hello ,

    Perhaps this old discuss on the forum can help you:
    Callback after audio file stopped playing :
    http://discussion.forum.nokia.com/fo...ad.php?t=69284

  4. #4
    Registered User
    Join Date
    Mar 2006
    Posts
    29

    Re: how to check if an audio file has stopped playing ?

    Quote Originally Posted by jplauril
    I didn't write the audio module, but I'm guessing that busy wait loop you have there doesn't give the audio object the opportunity to update its state. Try inserting e32.ao_yield() in the loop. That will run the active scheduler and process pending events.
    Wonderful ! This worked, so I can keep on writing my client. I guess I need to figure out the e32 module

    Thanks for your help !

  5. #5
    Registered User
    Join Date
    Mar 2006
    Posts
    29

    Re: how to check if an audio file has stopped playing ?

    anyone wants to listen to Radio Helsinki on a s60 phone ?

    Code:
    ##----------------------------------------
    ##
    ##      (very simple) client for ShoutCAST pys60
    ##      (c) MrKikkeli - 03/2006
    ##
    ##----------------------------------------
    
    import httplib, audio, e32, appuifw
    
    serveur = u'217.30.180.252'
    port = 80
    running = 1
    
    def quit():
        global running
        running = 0
        exit()
    
    appuifw.app.exit_key_handler = quit
    
    conn = httplib.HTTPConnection(serveur, port)
    conn.request('GET', '/')
    rep = conn.getresponse()
    
    ## lecture des 64 premiers ko
    header, stream = rep.read(64*128).split('\r\n\r\n')
    
    if header.split('\r\n')[0].find('200') != -1:
        buff2 = open('E:\\Others\\buff2.mp3', 'wb' )
        buff2.write(stream)
        buff2.close()
        while running:
            son = audio.Sound.open('E:\\Others\\buff2.mp3')
            son.play()
            buffun = open('E:\\Others\\buff1.mp3', 'wb' )
            while son.state() == 2:
                buffun.write(rep.read(1024))
                buffun.flush()
                e32.ao_yield()
            buffun.close()
            e32.ao_yield()
        #    son.close()
            son = audio.Sound.open('E:\\Others\\buff1.mp3')
            son.play()
            buff2 = open('E:\\Others\\buff2.mp3', 'wb' )
            while son.state() == 2:
                buff2.write(rep.read(1024))
                buff2.flush()
                e32.ao_yield()
            buff2.close()
            e32.ao_yield()
        #    son.close()
                      
    
    conn.close()
    It works, though you get a short, annoying gap when switching from a buffer file to another. I don't think this can be changed, but any idea is welcome !
    It'll be also needed to make sure the buffers don't grow exponentially in size. Maybe we can find the optimal buffer size if we know the download speed of the phone...

  6. #6
    Super Contributor
    Join Date
    Dec 2004
    Posts
    643

    Re: how to check if an audio file has stopped playing ?

    Hmm, both my phone (6630, with PyS60 1.3.1) and my PC raise an exception inside httplib.py at that rep.read(64*128)... line. Are you sure this is the code that worked for you?

  7. #7
    Registered User
    Join Date
    Mar 2006
    Posts
    29

    Re: how to check if an audio file has stopped playing ?

    I've just copy/pasted this code on the bluetooth console and it worked.

    I am using a nokia 6680. I've no idea why it doesn't work for you, since both 6680 and 6630 have python for s60 2nd Edition FP2

Similar Threads

  1. Playing AMR file is solved, Here is the solution.
    By khurshed79 in forum Symbian Media (Closed)
    Replies: 8
    Last Post: 2007-12-19, 06:11
  2. Replies: 0
    Last Post: 2005-09-09, 06:56
  3. Replies: 1
    Last Post: 2005-05-26, 14:22
  4. Playing an audio file on the open telephone line
    By Devang Shah in forum Symbian
    Replies: 1
    Last Post: 2005-02-27, 11:17
  5. Mixing and Matching of existing audio file?
    By hiteshw in forum Symbian
    Replies: 0
    Last Post: 2002-02-20, 02:28

Posting Permissions

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