Question

I am now using the Application to start recording as Android Service rather than the Main Thread. But after stopping the service using this : I cannot find the recording audio file

    stopService(new Intent(this,RecordService.class));
 //   stopService(new Intent(this,TimeService.class));
    Log.d("TAG" , "RecordSerivce finished");
    Log.d("TAG" , "TimeService finished");
    pd = ProgressDialog.show(Main4.this, "EOrder", "Uploading , please wait");  


     new Thread(new Runnable() {  
         @Override  
         public void run() {  
             spandTimeMethod();
             handler.sendEmptyMessage(0);                 
         }  

     }).start();  

The below is my code for the Service :

private MediaRecorder recorder;
@Override
public IBinder onBind(Intent arg0) {
    // TODO Auto-generated method stub
    return null;
}



@Override
public void onStart(Intent intent, int startId) {
    startRecording();       
    super.onStart(intent, startId);
}



@Override
public void onDestroy() {
    stopRecording();
    stopSelf();
    super.onDestroy();
}

private void startRecording(){

    try {
    recorder = new MediaRecorder();

    recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
    recorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
    recorder.setAudioEncoder(MediaRecorder.AudioEncoder.DEFAULT);


    Date today = Calendar.getInstance().getTime();    
    Format formatter = new SimpleDateFormat("yyyy-MM-dd_HH:mm:ss");
    String reportDate = formatter.format(today);


    File instanceRecordDirectory = new File(Environment.getExternalStorageDirectory() + File.separator + "sound");

    if(!instanceRecordDirectory.exists()){
        instanceRecordDirectory.mkdirs();
    }

    File instanceRecord = new File(instanceRecordDirectory.getAbsolutePath() + File.separator + reportDate + "_Recondsound.mp4");
    if(!instanceRecord.exists()){
        instanceRecord.createNewFile();
    }
    recorder.setOutputFile(instanceRecord.getAbsolutePath());



        recorder.prepare();
        recorder.start();
    } catch (IllegalStateException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }catch (Exception e){
          e.printStackTrace();
    }
}

private void stopRecording() {
    if (recorder != null) {       
        recorder.stop();
        recorder.release();
        recorder = null;
    }
}
Was it helpful?

Solution

I find the problem here

Format formatter = new SimpleDateFormat("yyyy-MM-dd_HH:mm:ss");

You must use this :

SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top