This article was reproduced from: http://blog.csdn.net/fnuwfnh/article/details/46698509
Recently in the learning of Android recording knowledge, found in some mobile phone normal operation of the app, on the Huawei Tablet hangs, Eclipse logcat display Mediarecorder start failed:-38. Check the information, because my app is encoded using multi-channel recording, and debugging with the Huawei tablet on the hardware can only single-track recording, does not support multi-channel recording. At present, MTK's 75,15,77,17 platform hardware only supports single-track recording, does not support multi-channel recording, the subsequent 89 platform in this piece has been improved, multi-channel recording needs hardware support, subsequent higher-order platform can support multi-channel recording. Pdxxxx is the Mtk77 platform, the hardware only supports single-track recording, does not support multi-channel recording.
The solution is to optimize the code to see if it can be adjusted from the code to one-way recording.
Here are two places in my app where mic source is used to play and save audio files while recording. On a mobile phone that supports multiple recordings, and on a platform that does not support multi-track recording, the test finds that it can only play on the recording side, or only the recording file, by changing the code. To save the audio file, you must release the mic SOURCE at the edge of the recording before start (it will take a while to delay).
Audiorecord AudioRecord2 =New Audiorecord (MediaRecorder.AudioSource.MIC, Frequency, channelconfiguration, audioencoding, RECBUFSI Ze); Audiotrack Audiotrack =New Audiotrack (Audiomanager.stream_music, Frequency, channelconfiguration, audioencoding, Playbufsize, Audiotrack.mode_stream);New Recordplaythread (). Start ();ClassRecordplaythreadExtendsThread {Publicvoid Run () {try {byte[] Buffer =NewBYTE[RECBUFSIZE2]; Audiorecord2.startrecording ();Start recording Audiotrack.play ();Start playbackwhile (isrecording) {Save data from mic to bufferint bufferreadresult = audiorecord2.read (buffer,0, RecBufSize2);byte[] Tmpbuf =NewByte[bufferreadresult]; System.arraycopy (Buffer,0, Tmpbuf,0, Bufferreadresult);//writing data is playing for (int I=0; i<buffer.length; i++) {Tmpbuf[i] = (byte) (Tmpbuf[i]*2);} audiotrack.write ( Tmpbuf, 0, tmpbuf.length); } audiotrack.stop (); Audiotrack.release (); Audiotrack = null; Audiorecord2.stop (); Audiorecord2.release (); audioRecord2 = null; } catch (Throwable t) {toast.maketext (Testoscilloscope. This, T.getmessage (), 1000); }}} //release the underlying resource //mrecorder.stop (); //mrecorder.release (); //mrecorder = null;
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21st
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
Mediarecorder Mrecorder = new Mediarecorder (); Mrecorder. Setaudiosource (Mediarecorder. Audiosource. MIC); Mrecorder. Setoutputformat (Mediarecorder. OutputFormat. DEFAULT); Mrecorder.setoutputfile (Second_path+date+;mrecorder.setaudioencoder (mediarecorder ;try {mrecorder.prepare () .E (Log_tag, "prepare () failed") .start () ;//release underlying resources//mrecorder.stop () ;//mrecorder.release () Span class= "hljs-comment" >;//mrecorder = Null;
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
Remember to release the underlying resources ~ Otherwise the app will not be able to get the underlying recording resources, thus unable to record, resulting in a run-time exception.
Android Mediarecorder start failed:-38 "Turn"