问题
There is some way to record audio on android wear? I used AudioRecord API and it crashes the application.
Am I doing something wrong?
short[] audioData = new short[minBufferSize];
AudioRecord audioRecord = new AudioRecord(MediaRecorder.AudioSource.MIC,
11025,
AudioFormat.CHANNEL_CONFIGURATION_MONO,
AudioFormat.ENCODING_PCM_16BIT,
minBufferSize);
audioRecord.startRecording();
while(recording){
int numberOfShort = audioRecord.read(audioData, 0, minBufferSize);
for(int i = 0; i < numberOfShort; i++){
dataOutputStream.writeShort(audioData[i]);
}
}
audioRecord.stop();
回答1:
AudioRecord is supported and works on Android Wear. If you are testing on an emulator it is possiblly not supporting the sample rate you are supplying, 11025, try another such as 8000.
After constructing AudioRecord, you should check the state to confirm initialization was successful before trying to record.
audioRecord.getState() == AudioRecord.STATE_INITIALIZED
Also ensure you have the correct permissions in the manifest. You will need android.permission.RECORD_AUDIO as a minimum and also any permissions for the location you are writing the file.
来源:https://stackoverflow.com/questions/28321405/how-to-record-audio-on-android-wear