Ich habe eine Tuner-App und mit Audio-Record-Objekt für das Hören von Mikrofon. Ich möchte verstehen, dass es gut funktioniert für die meisten Geräte und Android-Versionen (sogar Android 6), aber ich habe Fehlerbericht von Kunden auf Samsung S7-Handys. Ich habe ähnliche Beiträge hier angeschaut, um diesen Fehler zu vermeiden, und es hat mir sehr geholfen. Aber jetzt kann ich nicht verstehen, warum nur S7-Telefone diesen Fehler gibt, während es auf anderen Android 6 Geräten funktioniert.startRecording() rief eine nicht initialisierte AudioRecord auf Samsung S7 Telefone
P.S. Ich habe kein S7 Telefon, also könnte ich keine Chance haben, etwas zu versuchen. Ich frage mich nur, ob jemand ähnliche Probleme hat und was das Problem mit S7-Telefonen sein könnte. Irgendwelche Ideen?
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
initAudioRecord(44100, 2048);
.....
}
public void initAudioRecord(int sampleRateInHz, int bufferSizeInBytes) {
AudioRecord audioRecord = AudioRecordInstance(sampleRateInHz, bufferSizeInBytes);
if (audioRecord.getState() != AudioRecord.STATE_UNINITIALIZED) {
if (audioRecord.getRecordingState() != AudioRecord.RECORDSTATE_STOPPED) {
audioRecord.stop();
}
audioRecord.release();
audioRecord = AudioRecordInstance(sampleRateInHz, bufferSizeInBytes);
}
audioRecord.startRecording();
}
public AudioRecord AudioRecordInstance(int sampleRateInHz, int bufferSizeInBytes){
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M){
return new AudioRecord.Builder()
.setAudioSource(MediaRecorder.AudioSource.MIC)
.setAudioFormat(new AudioFormat.Builder()
.setEncoding(AudioFormat.ENCODING_PCM_16BIT)
.setSampleRate(sampleRateInHz)
.setChannelMask(AudioFormat.CHANNEL_IN_MONO)
.build())
.setBufferSizeInBytes(2*bufferSizeInBytes)
.build();
}else{
return new AudioRecord(
MediaRecorder.AudioSource.MIC,
sampleRateInHz,
AudioFormat.CHANNEL_IN_MONO,
AudioFormat.ENCODING_PCM_16BIT,
bufferSizeInBytes * 2);
}
}
}
LogCat:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.tuner/com.tuner.TunerActivity}: java.lang.IllegalStateException: startRecording() called on an uninitialized AudioRecord.
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3253)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3349)
at android.app.ActivityThread.access$1100(ActivityThread.java:221)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1794)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:158)
at android.app.ActivityThread.main(ActivityThread.java:7224)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
Bitte relevanten Code eingeben. Es ist nicht möglich, Ihre Frage so zu beantworten. –
hey ich habe den Code hinzugefügt. – uguboz
Bitte veröffentlichen Sie auch die Logcat-Ausgabe. –