In this post, I tried to play small audio data chunks with AudioTrack to show the feasibility of streaming audio. It's not straightforward enough. So I updated the sample code to actually transfer audio data with udp.
As the image below shows, the application is not too complicated.
The two buttons will each create a new thread to send and recv audio data respectively. And the sender will read audio data from the file /data/1.wav. Then, it sends the data to udp port 2048 on localhost. The receiver reads on 2048 port and feed data received to AudioTrack object.
Full code is available at:
http://code.google.com/p/rxwen-blog-stuff/source/browse/trunk/android/streaming_audio/src/rmd/media/StreamingAudio/UdpStream.java
thank you, that's exactly what I was looking for! :)
ReplyDeleteThanks for good example!
ReplyDeleteIs it possible to stream audio over OutputStream(bluetooth transfer capability). I can't find correct way how realize it. If you know tell me please direction =)
Regards..
hw do i get full duplex in this??
ReplyDeleteTo achieve full duplex, start receiver and sender threads on each peer simultaneously.
ReplyDeleteso instead f buttons n on click n dn calling - all i do is call both the func send and receive together rite??
ReplyDeletein dis fr prog 2 run do v need 2 do port forwarding also?? or jus run d code on 2 wifi conn machines ??
ReplyDeleteno need to set up port forwarding if these two devices are in the same lan.
ReplyDeletemy log cat shows byt_count but d receiving end aint playing d audio i hav sent from my sd card.. so isnt any ip addr required for directing d audio towards d odr end...
ReplyDelete01-27 16:20:24.968: D/UdpStream(345): btnSend clicked
ReplyDelete01-27 16:20:24.987: E/UdpStream(345): start send thread, thread id: 10
01-27 16:20:24.997: D/UdpStream(345): bytes_count : 800
01-27 16:20:25.073: D/UdpStream(345): bytes_count : 1600
01-27 16:20:25.143: D/UdpStream(345): bytes_count : 2400
01-27 16:20:25.213: D/UdpStream(345): bytes_count : 3200
01-27 16:20:25.287: D/UdpStream(345): bytes_count : 4000
01-27 16:20:25.367: D/UdpStream(345): bytes_count : 4800
01-27 16:20:25.440: D/UdpStream(345): bytes_count : 5600
01-27 16:20:25.517: D/UdpStream(345): bytes_count : 6400
01-27 16:20:25.588: D/UdpStream(345): bytes_count : 7200
01-27 16:20:25.658: D/UdpStream(345): bytes_count : 8000
01-27 16:20:25.728: D/UdpStream(345): bytes_count : 8800
01-27 16:20:25.799: D/UdpStream(345): bytes_count : 9600
01-27 16:20:25.877: D/UdpStream(345): bytes_count : 10400
dts my log cat in sending side n blank on receivers end!!
Could you please contact me on outtrylook@gmail.com
ReplyDeleteI tried to contact you but couldn't.
Anyway,
I am looking for a player which can play UDP and RTSP stream on android 2.2 platform.
Could u please help me regarding this?
Plase respond positively, Crossing my fingers and hoping for the best...
Thanks
I get a url multicast (udp, rtmp, mms..) (like IPTV)
ReplyDeleteCan I stream it on android ?
Please help.
This comment has been removed by the author.
ReplyDeleteHello,
ReplyDeleteI have understood that the audio data is PCM. I can compress the audio before sending via UDP?.
Yes, it's definitely possible. Just decode it at the receiving end before play a sample.
ReplyDeleteThank you so much. This works for me locally. However, when I tested it over the internet (using external/public ip) I have to do port forwarding. I am about to distribute the apk for testing purposes and I don't want to require each of them to manually do port forwarding. How can this be done without port forwarding?
ReplyDeleteHow can I download the streaming audio project folder and import to my android ADT? thanks!
ReplyDeletehow can i send voice stream from one android device to multiple android device via server??can u plz give me any reference or link??
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteI am trying on same phone, it just giving me noise.
ReplyDeleteI mean started receiving thread and then I started streaming thread.
It receives packets but only noise is coming not actual audio.
Please help.
I cant stop this thread and I dont know why.
ReplyDeleteWhen I send again, it overlap with the previous.
Can anyone solve my problem?
Thanks for your help
cannot access code.. can you please send me the code thanks
ReplyDelete