| Reply | « Previous Thread | Next Thread » |
|
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
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.
|
|
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.
|
|
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 |
|
Quote:
![]() Thanks for your help ! |
|
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'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... |
|
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?
|
|
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 | « Previous Thread | Next Thread » |
| Thread Tools | Search this Thread |
|---|---|
| Rate This Thread | |
| 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 |