我正在尝试从麦克风获取音频并通过连接到辅助设备的扬声器进行流式传输我使用了此代码,但它在录音机的初始化中不起作用,但我真正的问题是“这是正确的方法还是有更好的方法来做到这一点“如果是如何解决初始化音频的问题
public class MainActivity extends AppCompatActivity {
private static final String TAG = "MainActivity";
// the buttons for start and Stop BoadCast
Button mStartBoadCast;
Button mStopBoadCast;
// variables for audio recording
AudioRecord recorder;
private int sampleRate = 44100;
private int channelConfig = AudioFormat.CHANNEL_IN_DEFAULT;
private int audioFormat = AudioFormat.ENCODING_PCM_16BIT;
int minBufSize = AudioRecord.getMinBufferSize(sampleRate, channelConfig, audioFormat);
private boolean status = true;
// audio instance is meant for playing audio input from stream
private AudioTrack speaker;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//init layout views
initViews();
// init start boadcast method with the button
initStartBoadCast();
// init stop boadcast method with the button
initStartBoadCast();
}
private void initStartBoadCast() {
mStartBoadCast.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startBoadCast();
}
});
}
private void initStopBoadCast() {
mStartBoadCast.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
stopBoadCast();
}
});
}
private void stopBoadCast() {
//todo: add the function to stop boad casr
status = false;
recorder.release();
speaker.release();
}
FFIVE
相关分类