android 应用程序中的 Youtube 直播中出现音频问题

Getting Audio issue in Youtube Live streaming in android application

我正在 android 直播中开发应用程序。我能够将实时视频流式传输到 YouTube 频道。但问题是,该直播视频没有音频。

我的代码如下所示

 private static final int frequency= 44100;
     public void recordThread() {
            Log.d(MainActivity.APP_NAME, "recordThread");

            int audioEncoding = AudioFormat.ENCODING_PCM_16BIT;
            int channelConfiguration = AudioFormat.CHANNEL_IN_STEREO;
            int bufferSize = AudioRecord.getMinBufferSize(frequency, channelConfiguration, audioEncoding);
            Log.i(MainActivity.APP_NAME, "AudioRecord buffer size: " + bufferSize);

            // 16 bit PCM stereo recording was chosen as example.
            AudioRecord recorder = new AudioRecord(MediaRecorder.AudioSource.MIC, frequency, channelConfiguration,
                    audioEncoding, bufferSize);
            recorder.startRecording();

            // Make bufferSize be in samples instead of bytes.
            bufferSize /= 2;
            short[] buffer = new short[bufferSize];
            while (!cancel) {
                int bufferReadResult = recorder.read(buffer, 0, bufferSize);
                // Utils.Debug("bufferReadResult: " + bufferReadResult);
                if (bufferReadResult > 0) {
                    frameCallback.handleFrame(buffer, bufferReadResult);
                } else if (bufferReadResult < 0) {
                    Log.w(MainActivity.APP_NAME, "Error calling recorder.read: " + bufferReadResult);
                }
            }
            recorder.stop();

            Log.d(MainActivity.APP_NAME, "exit recordThread");
        }

请给我一些解决此问题的建议。

在 github 中搜索。在那里你会找到一个用于音频编码的示例项目(yasea)。混合这两个项目,你会得到解决方案。