I am trying to multicast an audio stream from one device to many others using Android's RTP classes.
I do not want to use any third party libraries if at all possible.
I am able to stream two way audio between two devices using AudioStream
and AudioGroup
set up with each other's IP addresses, but I would like to stream to a multicast group.
If I try to instantiate the AudioStream
with a multicast address such as 239.1.1.1
and then, on the other device use audioStream.associate()
with the same multicast address, but the streams are not heard.
I have read about some Android devices not supporting multicast, but my devices (both Samsung Galaxy Tab 2s) do support it. I have even added the following to my code to try to obtain a multicast lock:
WifiManager wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);
multicastLock = wifi.createMulticastLock("multicastLock");
multicastLock.setReferenceCounted(true);
multicastLock.acquire();
Additionally I have the following permissions in my manifest file:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_MULTICAST_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
After looking into this a lot, I have discovered that the RTP classes do support sending multicast, but not receiving. Presumably this is because the sockets that get used are not MulticastSocket
s.
Also, for those interested, the Tab 2 is in fact one of the devices that doesn't support joining multicast groups (i.e. it does not send IGMP join packets), but if you set up static multicast groups in your network infrastructure, then the packets will be received - hence why I mentioned above that I knew that they do support it.
A quick way of seeing if an Android device supports joining multicast groups is by looking for the presence of the /proc/net/igmp
file.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With