मैं एंड्रॉइड में ऑडियो रिकॉर्ड करने की कोशिश कर रहा हूं लेकिन मुझे एक समस्या का सामना करना पड़ रहा है।ऑडियो रिकॉर्ड करने की कोशिश कर रहा है लेकिन संदेश प्राप्त करना "मीडियारेकॉर्डर अनचाहे घटनाओं से दूर चला गया" और "घातक सिग्नल 11 (एसआईजीएसईजीवी) ...."
मैंने बटन शुरू और बंद कर दिया है, रिकॉर्डिंग शुरू करने के लिए "शुरू करें" और रिकॉर्डिंग को रोकने के लिए "रोकें"।
समस्या यह है कि, जब मैं स्टॉप बटन दबाता हूं तो मेरा एप्लिकेशन एक संदेश "डब्ल्यू/मीडियाआरकॉर्डर (635) लॉग करता है: मीडियारेकॉर्डर अनचाहे घटनाओं से दूर चला गया"। (स्टार्ट फ़ंक्शन ऑडियो फ़ाइल को ठीक से सहेज रहा है।)
फिर, यदि मैं फिर से स्टार्ट या स्टॉप बटन दबाता हूं तो मुझे त्रुटि संदेश मिलता है "ए/libc (743): 0x00000010 पर घातक सिग्नल 11 (एसआईजीएसईजीवी) (कोड = 1), धागा 743 (xample.recorder) "रिकॉर्डिंग वर्ग के
कोड के नीचे है:
/**
* Creates a new audio recording at the given path (relative to root of SD card).
*/
public AudioRecorder(String path) {
this.path = sanitizePath(path);
}
private String sanitizePath(String path) {
if (!path.startsWith("/")) {
path = "/" + path;
}
if (!path.contains(".")) {
path += ".3gp";
}
return Environment.getExternalStorageDirectory().getAbsolutePath() + path;
}
public void start() throws IOException {
String state = android.os.Environment.getExternalStorageState();
if(!state.equals(android.os.Environment.MEDIA_MOUNTED)) {
throw new IOException("SD Card is not mounted. It is " + state + ".");
}
// make sure the directory we plan to store the recording in exists
File directory = new File(path).getParentFile();
if (!directory.exists() && !directory.mkdirs()) {
throw new IOException("Path to file could not be created.");
}
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
recorder.setOutputFile(path);
try{
recorder.prepare();
}
catch(IOException e){
Log.e("Recorder","Recording failed");
}
recorder.start();
}
/**
* Stops a recording that has been previously started.
*/
public void stop() throws IOException {
recorder.stop();
recorder.release();
}
मुख्य गतिविधि संहिता के नीचे है:
/*
* */
public class Recorder extends Activity implements OnClickListener
{
private static final String TAG="Recorder";
AudioRecorder ar=new AudioRecorder("/TestAudio.3gp");
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_recorder);
final Button start = (Button) this.findViewById(R.id.btn_start);
start.setOnClickListener(this);
final Button stop = (Button) this.findViewById(R.id.btn_stop);
stop.setOnClickListener(this);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_recorder, menu);
return true;
}
public void onClick(View v) {
// TODO Auto-generated method stub
try{
switch (v.getId()) {
case R.id.btn_start:
ar.start();
Log.d("Recorder","Recorded");
Toast.makeText(this, "Controll returned from start function", Toast.LENGTH_LONG).show();
break;
case R.id.btn_stop:
ar.stop();
Toast.makeText(this, "Recording stopped; Starting MediaPlayer", Toast.LENGTH_SHORT).show();
//Toast.makeText(this, "Starting media player", Toast.LENGTH_LONG).show();
ar.startPlaying();
//Toast.makeText(this, "Recording stopped", Toast.LENGTH_LONG).show();
break;
}
}
catch(Exception e){
Log.e("Recorder", e.getMessage(), e);
Toast.makeText(this, e.getMessage(), Toast.LENGTH_LONG).show();
}
}
}
यह पूरा कोड नहीं है? मैं यहाँ निर्माता को नहीं देखता रिकॉर्डर = नया MediaRecorder(); सभी स्टैकट्रैक दिखाएं, क्या आपको एक और अपवाद मिला? – dimetil
मैंने इस ट्यूटोरियल का इस्तेमाल किया http://www.benmccann.com/dev-blog/android-audio-recording-tutorial/ प्रारंभ बटन में मैं फ़ंक्शन शुरू करता हूं और स्टॉप बटन में मैं फ़ंक्शन स्टॉप को कॉल करता हूं ... दबाने के बाद प्रारंभ बटन, मैं स्टॉप दबाता हूं और फिर यदि मैं फिर से स्टार्ट बटन दबाता हूं तो मुझे त्रुटि संदेश मिलता है "ए/libc (743): 0x00000010 (कोड = 1) पर घातक सिग्नल 11 (SIGSEGV), थ्रेड 743 (xample.recorder)" – blackfyre
मेरा फिक्स https: // stackoverflow।कॉम/ए/47 992111/45 9 2448 – Fortran