2015-04-16 73 views
4

我正在使用Java將rtp音頻從麥克風傳輸到我的android手機應用程序,但我沒有聽到任何聲音。設置AudioGroup和AudioStream時沒有錯誤,因此我假定一切都正確。這裏是關於應用程序端的代碼:如何接收RTP音頻流Android?

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工程)是

ffmpeg -f lavfi -i aevalsrc="sin(400*2*PI*t)" -ar 8000 -vcodec pcm_u8 -f rtp rtp://163.11.62.208:5004 

再次..這工作在VLC播放器的Android而不是在我的應用程序沒有錯誤..只是沒有音頻。

好吧我只是注意到在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 

但是:我也只是注意到,我運行我的應用程序時根本沒有系統音量。當我改變系統音量時,它通常會顯示一個指示器噪音,以顯示這是多麼大聲/安靜,但我什麼也聽不到。我不確定這是爲什麼。

+0

不要求嚴格模式關閉網絡。它在現代設備上根本無法工作,並且可能導致問題。如果您需要聯網,請使用線程或AsyncTask。 –

+0

好吧,我已經改變了,但我似乎還沒有得到任何音量。我也將代碼移入一個單獨的線程。 –

+0

凹凸。在這裏有同樣的問題...如果我嘗試從MODE_RECEIVE_ONLY從MODE_SEND_ONLY'setMode',我得到'IllegalStateException:busy' :( –

回答

1

確保您的清單中包含<uses-permission android:name="android.permission.RECORD_AUDIO" />

我打賭你可能已經這麼做了,所以請去Settings -> Apps -> (Click the Gear) -> App Permissions -> Microphone並確保它已經開啓了你的應用程序。

我花了很長時間才弄明白這一點,因爲我在清單中的權限有同樣的問題。

相關問題