本篇简单介绍一下手机直播解决方案EasyPusher是怎么获取AAC音频的。思路大概就是使用AudioRecord录音,然后将每一帧数据通过MediaCodec编码成LATM格式音频,最后转换为ADTS格式的AAC数据,然后就发送给服务器就OK了。
看一下录音的代码:
public void startRecord() {
try {
init();
mAudioRecord.startRecording();
mMediaCodec.start();
final ByteBuffer[] inputBuffers = mMediaCodec.getInputBuffers();
mThread = new Thread(new Runnable() {
@Override
public void run() {
Process.setThreadPriority(Process.THREAD_PRIORITY_AUDIO);
int len = 0, bufferIndex = 0;
try {
while (!Thread.interrupted() && !stoped) {
bufferIndex = mMediaCodec.dequeueInputBuffer(50000);
i