2012-04-13 20 views
8

मुझे एक बहुत ही अजीब व्यवहार का सामना करना पड़ा है: कभी-कभी मेरा मीडियारेकॉर्डर "विफल होना बंद करें" त्रुटि के साथ दुर्घटनाग्रस्त हो जाता है और कभी-कभी यह ठीक काम करता है। क्या मेरी गलती है या यह सिस्टम की एक बग है? मुझे गलत नहीं मिल सकता है।एंड्रॉइड मीडियारेकॉर्डर स्टॉप असफल

private void stopRecording(){ 
     ticker.cancel(); 
     ticker.purge(); 

     recorder.stop(); 

     startBtn.setText("Start"); 
     recordInProcess = false; 

     markList = locWriteTask.getMarkArray(); 

    mCamera.lock(); 
     recorder.release(); 
    } 

private void startRecording(){ 

     startBtn.setText("Stop"); 

     recordInProcess = true; 

      recorder = new MediaRecorder(); 

     mCamera.unlock(); 
     recorder.setCamera(mCamera); 

     recorder.setPreviewDisplay(mSurfaceHolder.getSurface()); 
     recorder.setAudioSource(MediaRecorder.AudioSource.MIC); 
     recorder.setVideoSource(MediaRecorder.VideoSource.CAMERA); 
     recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP); 
     recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB); 
     recorder.setVideoEncoder(MediaRecorder.VideoEncoder.MPEG_4_SP); 
     recorder.setMaxDuration((int) 10000000); 
     recorder.setVideoSize(320, 240); 
     recorder.setVideoFrameRate(15); 
     recorder.setOutputFile(FULL_PATH_TO_LOCAL_FILE + counter + MP4); 

     try{ 
      recorder.prepare(); 
     } catch (Exception e){ 
      finish(); 
     } 

     lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, ll); 

     ticker = new Timer(); 
     locWriteTask = new WriteTimeLocationTimerTask(ll); 
     ticker.schedule(locWriteTask, 0, DELAY); 

     recorder.start(); 
    } 

उत्तर

2

रिकॉर्डर एक रिकॉर्डिंग की स्थिति में नहीं है, तो रोक विफल हो सकता है।

http://developer.android.com/reference/android/media/MediaRecorder.html

+15

मैं कैसे जांचता हूं कि MediaRecorder एक रिकॉर्डिंग स्थिति में है? – Kalpesh

+0

@ कालपेश मीडियारेकॉर्डर एपीआई में दुर्भाग्यवश अपने राज्य से पूछताछ करने का प्रावधान नहीं है। – Bhargav

8

देखें आप विधि MediaRecorder.stop() में RuntimeException को पकड़ सकता है।

उदाहरण:

MediaRecorder mRecorder = new MediaRecorder(); 
File mFile = new File("The output file's absolutePath"); 

... //config the mRecorder 
mRecorder.setOutputFile(mFile.getAbsolutePath()); 

... //prepare() ... 
mRecorder.start(); 

try { 
    mRecorder.stop(); 
} catch(RuntimeException e) { 
    mFile.delete(); //you must delete the outputfile when the recorder stop failed. 
} finally { 
    mRecorder.release(); 
    mRecorder = null; 
} 
2

ऐड अपने SurfaceCreated (SurfaceHolder धारक) में निम्नलिखित: कभी कभी मेरे MediaRecorder एक त्रुटि के साथ दुर्घटनाग्रस्त हो गया "बंद विफल" और कभी कभी यह:

CamcorderProfile camcorderProfile = CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH); //get your own profile 
Camera.Parameters parameters = mCamera.getParameters(); 
parameters.setPreviewSize(camcorderProfile.videoFrameWidth,camcorderProfile.videoFrameHeight); 
mCamera.setParameters(parameters); 
+0

यह ठीक करने के लिए क्या माना जाता है? – StarShine

0

वही त्रुटि अनुभवी ठीक काम किया इस समस्या को हल करने में मेरी समस्या:

@Override 
public void onStop() { 
    super.onStop(); 
    if (mRecorder != null) { 
     mRecorder.release(); 
     mRecorder = null; 
    } 
} 
+0

यह वास्तव में क्या जोड़ रहा है? – StarShine

संबंधित मुद्दे