我想录制现场音频,然后将其传输到PC,然后在PC上播放。
我在网上找到了一个样本。
public class Saudioclient extends Thread {
protected AudioRecord m_in_rec;
protected int m_in_buf_size;
protected byte[] m_in_bytes;
protected boolean m_keep_running;
protected Socket s;
protected DataOutputStream dout;
protected LinkedList<byte[]> m_in_q;
public void run() {
try {
byte[] bytes_pkg;
m_in_rec.startRecording();
while (m_keep_running) {
m_in_rec.read(m_in_bytes, 0, m_in_buf_size);
bytes_pkg = m_in_bytes.clone();
if (m_in_q.size() >= 2) {
dout.write(m_in_q.removeFirst(), 0,
m_in_q.removeFirst().length);
}
m_in_q.add(bytes_pkg);
}
m_in_rec.stop();
m_in_rec = null;
m_in_bytes = null;
dout.close();
} catch (Exception e) {
e.printStackTrace();
}
}
public void init() {
m_in_buf_size = AudioRecord.getMinBufferSize(8000,
AudioFormat.CHANNEL_CONFIGURATION_MONO,
AudioFormat.ENCODING_PCM_16BIT);
m_in_rec = new AudioRecord(MediaRecorder.AudioSource.MIC, 8000,
AudioFormat.CHANNEL_CONFIGURATION_MONO,
AudioFormat.ENCODING_PCM_16BIT, m_in_buf_size);
m_in_bytes = new byte[m_in_buf_size];
m_keep_running = true;
m_in_q = new LinkedList<byte[]>();
try {
s = new Socket("192.168.1.100", 4332);
dout = new DataOutputStream(s.getOutputStream());
// new Thread(R1).start();
} catch (UnknownHostException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
Android设备仍然响起。这不是我想要的。我希望现场音频只在PC上播放,而不是在Android设备上播放。
有什么建议吗?