I want to stream audio (opus codec) with ffmpeg directly to android device.
On PC i start stream:
./ffmpeg -re -stream_loop -1 -i akgld-c8mxm.opus -acodec libopus -ac 1 -ab 96k -vn -f rtp rtp://192.168.0.100:6000
Where 192.168.0.100 - local wifi address of my phone.
On Android device i tried to play stream:
public void tryPlayStream() {
String ip = Utils.wifiIpAddress(this);
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitNetwork().build();
StrictMode.setThreadPolicy(policy);
AudioManager audio = (AudioManager) getSystemService(AUDIO_SERVICE);
audio.setMode(AudioManager.MODE_IN_COMMUNICATION);
audioGroup = new AudioGroup();
audioGroup.setMode(AudioGroup.MODE_ECHO_SUPPRESSION);
InetAddress inetAddress;
try {
inetAddress = InetAddress.getByName(ip);
audioStream = new AudioStream(inetAddress);
audioStream.setCodec(AudioCodec.PCMA);
audioStream.setMode(RtpStream.MODE_RECEIVE_ONLY);
InetAddress inetAddressRemote = InetAddress.getByName(ip);
audioStream.associate(inetAddressRemote, 6000);
audioStream.join(audioGroup);
} catch (Exception e) {
e.printStackTrace();
}
}
In logcat i see next lines:
E/AudioRecord: AudioFlinger could not create record track, status: -1
E/AudioGroup: cannot initialize audio device
What im doing wrong? Thanks for any help
With RTP you start a streaming server on your PC. So in your ffmpeg commandline you have to specify your PC's IP address and not the target:
./ffmpeg -re -stream_loop -1 -i akgld-c8mxm.opus -acodec libopus -ac 1 -ab 96k -vn -f rtp rtp://YOUR_PC_S_IP_ADDRESS:6000
On the Android side you'll need a RTP/RTSP client. I'd try: https://github.com/pedroSG94/rtmp-rtsp-stream-client-java
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