我正在尝试通过多部分 HTTP 流从 Axis 网络安全摄像头流式传输实时音频,该流在 Android 手机上以 g711 ulaw 8 khz、8 位样本编码。看起来这应该很简单,这是我的代码的基础。我重用了一些从 MJPEG 流中抓取 JPEG 帧的流代码,现在它抓取 512 字节的音频数据块并将其传递给 AudioTrack。音频听起来都是乱码和失真,我是否遗漏了一些明显的东西?
@Override
public void onResume() {
super.onResume();
int bufferSize = AudioTrack.getMinBufferSize(8000, AudioFormat.CHANNEL_OUT_MONO, AudioFormat.ENCODING_PCM_8BIT);
mAudioTrack = new AudioTrack(AudioManager.STREAM_MUSIC, 8000, AudioFormat.CHANNEL_OUT_MONO, AudioFormat.ENCODING_PCM_8BIT, bufferSize, AudioTrack.MODE_STREAM);
mAudioTrack.play();
thread.start();
}
class StreamThread extends Thread {
public boolean running = true;
public void run() {
try {
MjpegStreamer streamer = MjpegStreamer.read("/axis-cgi/audio/receive.cgi?httptype=multipart");
while(running) {
byte[] buf = streamer.readMjpegFrame();
if(buf != null && mAudioTrack != null) {
mAudioTrack.write(buf, 0, buf.length);
}
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}