You Are Here:

Community: Developer Discussion Boards

#1 Old [solved]how to check if an audio file has stopped playing ? - 2006-03-20, 16:54

Join Date: Mar 2006
Posts: 29
MrKikkeli's Avatar
MrKikkeli
Offline
Registered User
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 18:31. Reason: problem solved.
Reply With Quote

#2 Old Re: how to check if an audio file has stopped playing ? - 2006-03-20, 17:30

Join Date: Dec 2004
Posts: 646
jplauril's Avatar
jplauril
Offline
Forum Nokia Expert
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.
Reply With Quote

#3 Old Re: how to check if an audio file has stopped playing ? - 2006-03-20, 17:46

Join Date: Feb 2005
Posts: 1,353
Location: Belgium (Europe)
cyke64's Avatar
cyke64
Offline
Super Contributor
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
Reply With Quote

#4 Old Re: how to check if an audio file has stopped playing ? - 2006-03-20, 18:01

Join Date: Mar 2006
Posts: 29
MrKikkeli's Avatar
MrKikkeli
Offline
Registered User
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 !
Reply With Quote

#5 Old Re: how to check if an audio file has stopped playing ? - 2006-03-20, 23:30

Join Date: Mar 2006
Posts: 29
MrKikkeli's Avatar
MrKikkeli
Offline
Registered User
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...
Reply With Quote

#6 Old Re: how to check if an audio file has stopped playing ? - 2006-03-21, 10:52

Join Date: Dec 2004
Posts: 646
jplauril's Avatar
jplauril
Offline
Forum Nokia Expert
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?
Reply With Quote

#7 Old Re: how to check if an audio file has stopped playing ? - 2006-03-21, 15:08

Join Date: Mar 2006
Posts: 29
MrKikkeli's Avatar
MrKikkeli
Offline
Registered User
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
Reply With Quote
Reply « Previous Thread | Next Thread »
Display Modes
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules

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

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump
Similar Threads
Thread Thread Starter Forum Replies Last Post
Playing AMR file is solved, Here is the solution. khurshed79 Symbian Media (Graphics & Sounds) 8 2007-12-19 07:11
symbianyucca, could you please check this code for audio streaming? khurshed79 General Symbian C++ 0 2005-09-09 07:56
What is the error in my code here? Unable to Save document to file yuva69 General Symbian C++ 1 2005-05-26 15:22
Playing an audio file on the open telephone line Devang Shah General Symbian C++ 1 2005-02-27 12:17
Mixing and Matching of existing audio file? hiteshw General Symbian C++ 0 2002-02-20 03:28

Rate This

 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditDiigoTechnocratiTwitter  Share this page Share this page Print this Page Print this page Invite a friend Invite a friend
京ICP备05048969号    Email Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us © 2009 Nokia