Java Android如何接收RTP音频流?
我正在使用Java将rtp音频从麦克风传输到我的android手机应用程序,但我没有听到任何声音。设置AudioGroup和AudioStream时没有错误,因此我假设一切正常。以下是应用程序端的代码:Java Android如何接收RTP音频流?,java,android,audio,streaming,rtp,Java,Android,Audio,Streaming,Rtp,我正在使用Java将rtp音频从麦克风传输到我的android手机应用程序,但我没有听到任何声音。设置AudioGroup和AudioStream时没有错误,因此我假设一切正常。以下是应用程序端的代码: AudioStream audioStream; AudioGroup audioGroup; AudioCodec codec = AudioCodec.PCMU; StrictMode.ThreadPolicy policy = new StrictMode.
AudioStream audioStream;
AudioGroup audioGroup;
AudioCodec codec = AudioCodec.PCMU;
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_NORMAL);
InetAddress inetAddress;
try {
inetAddress = InetAddress.getByName("163.11.62.208");
audioStream = new AudioStream(inetAddress);
audioStream.setMode(RtpStream.MODE_RECEIVE_ONLY);
audioStream.setCodec(codec);
InetAddress inetAddressRemote = InetAddress.getByName("163.11.169.206");
audioStream.associate(inetAddressRemote, 5004);
audioStream.join(audioGroup);
}
我使用的ffmpeg流测试(在vlc Android播放器上工作)是
再一次。。这在VLC android player中有效,但在我的应用程序中无效。没有错误。。只是没有音频
好的,我刚刚在LogCat中注意到,我收到消息,告诉我它正在工作。这是一些日志
stream[59] is configured as RAW 8kHz 32ms mode 0
D/AudioGroup﹕ stream[59] joins group[56]
group[56] switches from mode 0 to 1
stream[54] joins group[56]
getOutputSamplingRate() reading from output desc
V/AudioSystem﹕ getSamplingRate() streamType 0, output 2, sampling rate 48000
V/AudioSystem﹕ getFrameCount() streamType 0, output 2, frameCount 960
V/AudioSystem﹕ getLatency() streamType 0, output 2, latency 160
V/AudioTrack﹕ getMinFrameCount=1280: afFrameCount=960, minBufCount=8, afSampleRate=48000, afLatency=160
D/AudioGroup﹕ reported frame count: output 1280, input 320
D/AudioGroup﹕ adjusted frame count: output 1280, input 512
V/AudioTrack﹕ sampleRate 8000, channelMask 0x1, format 1
V/AudioTrack﹕ streamType 0
V/AudioTrack﹕ set() streamType 0, sampleRate 8000, format 1, frameCount 1280, flags 0000
V/AudioSystem﹕ getLatency() streamType 0, output 2, latency 160
V/AudioSystem﹕ getFrameCount() streamType 0, output 2, frameCount 960
V/AudioSystem﹕ getOutputSamplingRate() reading from output desc
V/AudioSystem﹕ getSamplingRate() streamType 0, output 2, sampling rate 48000
V/AudioTrack﹕ createTrack_l() output 2 afLatency 160
V/AudioTrack﹕ afFrameCount=960, minBufCount=8, afSampleRate=48000, afLatency=160
V/AudioTrack﹕ minFrameCount: 1280, afFrameCount=960, minBufCount=8, sampleRate=8000, afSampleRate=48000, afLatency=160
V/AudioRecord﹕ sampleRate 8000, channelMask 0x10, format 1
V/AudioRecord﹕ inputSource 7
V/AudioRecord﹕ set(): sampleRate 8000, channelMask 0x10, frameCount 512
D/AudioRecord﹕ set(): voiceActivationState 0
D/AudioRecord﹕ Keep input Source type.
V/AudioRecord﹕ AudioRecord::set() minFrameCount = 320
V/AudioRecord﹕ set(): mSessionId 1827
V/AudioSystem﹕ ioConfigChanged() event 3, ioHandle 1828
但是:我还注意到,在运行我的应用程序时,我根本没有系统卷。当我改变系统音量时,它通常会发出指示噪音,以显示声音有多大/多安静,但我什么也听不到。我不知道这是为什么。确保您的清单中有
我打赌你可能已经这样做了,所以请转到设置->应用->(单击齿轮)->应用权限->麦克风,并确保你的应用已打开
我花了很长时间才弄明白这一点,因为清单中的权限也存在同样的问题。不要请求严格模式来关闭网络。它在现代设备上根本不起作用,这很可能是问题的原因。如果你需要联网,可以使用线程或异步任务。好的,我已经改变了,但是我仍然没有得到卷。我还将代码移动到一个单独的thread.Bump中。这里也有同样的问题。。。如果我尝试从模式下设置模式,只从模式下接收,只从模式下发送,我会得到非法状态异常:忙(好的,非法状态异常
已修复,但仍然没有来自服务器的环回声音。@TylerHelmuth解决此问题的运气好吗?
stream[59] is configured as RAW 8kHz 32ms mode 0
D/AudioGroup﹕ stream[59] joins group[56]
group[56] switches from mode 0 to 1
stream[54] joins group[56]
getOutputSamplingRate() reading from output desc
V/AudioSystem﹕ getSamplingRate() streamType 0, output 2, sampling rate 48000
V/AudioSystem﹕ getFrameCount() streamType 0, output 2, frameCount 960
V/AudioSystem﹕ getLatency() streamType 0, output 2, latency 160
V/AudioTrack﹕ getMinFrameCount=1280: afFrameCount=960, minBufCount=8, afSampleRate=48000, afLatency=160
D/AudioGroup﹕ reported frame count: output 1280, input 320
D/AudioGroup﹕ adjusted frame count: output 1280, input 512
V/AudioTrack﹕ sampleRate 8000, channelMask 0x1, format 1
V/AudioTrack﹕ streamType 0
V/AudioTrack﹕ set() streamType 0, sampleRate 8000, format 1, frameCount 1280, flags 0000
V/AudioSystem﹕ getLatency() streamType 0, output 2, latency 160
V/AudioSystem﹕ getFrameCount() streamType 0, output 2, frameCount 960
V/AudioSystem﹕ getOutputSamplingRate() reading from output desc
V/AudioSystem﹕ getSamplingRate() streamType 0, output 2, sampling rate 48000
V/AudioTrack﹕ createTrack_l() output 2 afLatency 160
V/AudioTrack﹕ afFrameCount=960, minBufCount=8, afSampleRate=48000, afLatency=160
V/AudioTrack﹕ minFrameCount: 1280, afFrameCount=960, minBufCount=8, sampleRate=8000, afSampleRate=48000, afLatency=160
V/AudioRecord﹕ sampleRate 8000, channelMask 0x10, format 1
V/AudioRecord﹕ inputSource 7
V/AudioRecord﹕ set(): sampleRate 8000, channelMask 0x10, frameCount 512
D/AudioRecord﹕ set(): voiceActivationState 0
D/AudioRecord﹕ Keep input Source type.
V/AudioRecord﹕ AudioRecord::set() minFrameCount = 320
V/AudioRecord﹕ set(): mSessionId 1827
V/AudioSystem﹕ ioConfigChanged() event 3, ioHandle 1828