Exemple #1
0
 private void releaseMediaRecorder() {
   if (recorder != null) {
     recorder.reset();
     recorder.release();
     recorder = null;
   }
 }
Exemple #2
0
 /** M: set Recorder to initial state */
 public boolean reset() {
   /** M:modified for stop recording failed. @{ */
   boolean result = true;
   synchronized (this) {
     if (null != mRecorder) {
       try {
         /** M: To avoid NE while mCurrentState is not prepared.@{* */
         if (mCurrentState == SoundRecorderService.STATE_PAUSE_RECORDING
             || mCurrentState == SoundRecorderService.STATE_RECORDING) {
           mRecorder.stop();
         }
         /** @}* */
       } catch (RuntimeException exception) {
         exception.printStackTrace();
         result = false;
         LogUtils.e(TAG, "<stopRecording> recorder illegalstate exception in recorder.stop()");
       } finally {
         mRecorder.reset();
         mRecorder.release();
         mRecorder = null;
       }
     }
   }
   mSampleFile = null;
   mPreviousTime = 0;
   mSampleLength = 0;
   mSampleStart = 0;
   /** M: add for some error case for example pause or goon recording failed. @{ */
   mCurrentState = SoundRecorderService.STATE_IDLE;
   /** @} */
   return result;
 }
  @Override
  public boolean onTouchEvent(MotionEvent event) {
    if (event.getAction() == MotionEvent.ACTION_DOWN) {
      if (!_isRecording) {
        _recorder.setVideoSource(MediaRecorder.VideoSource.DEFAULT);
        _recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
        _recorder.setVideoEncoder(MediaRecorder.VideoEncoder.DEFAULT);

        _recorder.setVideoEncodingBitRate(10000000);

        _recorder.setVideoFrameRate(5);

        _recorder.setVideoSize(100, 100);

        _recorder.setOutputFile("/sdcard/sample.3gp");
        _recorder.setPreviewDisplay(_holder.getSurface());

        try {
          _recorder.prepare();
        } catch (Exception e) {
          Log.e("test", "recorder error");
        }
        _recorder.start();
        _isRecording = true;

      } else {
        _recorder.stop();
        _recorder.reset();
        _isRecording = false;
      }
    }
    return true;
  }
Exemple #4
0
 public void stop() {
   if (started) {
     mRecorder.stop();
     mRecorder.reset();
     started = false;
   }
 }
 private void releaseMediaRecorder() {
   if (mMediaRecorder != null) {
     mMediaRecorder.reset();
     mMediaRecorder.release();
     mMediaRecorder = null;
     camera.lock();
   }
 }
 private void releaseMediaRecorder() {
   if (mMediaRecorder != null) {
     mMediaRecorder.reset(); // clear recorder configuration
     mMediaRecorder.release(); // release the recorder object
     mMediaRecorder = null;
     mCamera.lock(); // lock camera for later use
   }
 }
 public void stopRecording() {
   if (CallRecording.isRecording) {
     mediaRecorder.stop();
     mediaRecorder.reset();
     mediaRecorder.release();
     mediaRecorder = null;
     isRecording = false;
   }
 }
 /** Stops a recording that has been previously started. */
 public void stopRecorder() throws IOException {
   isRecordingStart = false;
   if (recorder != null) {
     recorder.stop();
     // recorder.stop();
     recorder.reset();
     recorder.release();
     recorder = null;
   }
   // recorder.release();
 }
  public void stopRecording() {

    Log.v("Timeusing", "녹음중지");
    try {
      recorder.stop();
      recorder.reset();

    } catch (RuntimeException stopException) {
      // recorder.stop();
      // do it
    }
  }
Exemple #10
0
 private void stopRecording() {
   prMediaRecorder.stop();
   prMediaRecorder.reset();
   try {
     prCamera.reconnect();
   } catch (IOException e) {
     e.printStackTrace();
   }
   btnStartRecorder.setText("Start");
   prRecordInProcess = false;
   prCamera.startPreview();
 }
Exemple #11
0
 private void releaseMediaRecorder() {
   if (mMediaRecorder != null) {
     // clear recorder configuration
     mMediaRecorder.reset();
     // release the recorder object
     mMediaRecorder.release();
     mMediaRecorder = null;
     // Lock camera for later use i.e taking it back from MediaRecorder.
     // MediaRecorder doesn't need it anymore and we will release it if the activity pauses.
     mCamera.lock();
   }
 }
Exemple #12
0
 /** M: Handle Exception when call the function of MediaRecorder */
 public void handleException(boolean isDeleteSample, Exception exception) {
   LogUtils.i(TAG, "<handleException> the exception is: " + exception);
   exception.printStackTrace();
   if (isDeleteSample && mSampleFile != null) {
     mSampleFile.delete();
   }
   if (mRecorder != null) {
     mRecorder.reset();
     mRecorder.release();
     mRecorder = null;
   }
 }
 public static void stopRecording() {
   if (mRecorder != null) {
     Log.i(AnkiDroidApp.TAG, "Recording stopped " + mCacheFile.getPath());
     mRecorder.stop();
     mRecorder.reset();
     mRecorder.release();
     mRecorder = null;
     // trigger listener
     if (mFinishedListener != null) {
       mFinishedListener.onRecordingFinished();
     }
   }
 }
 public void stop() {
   if (streaming) {
     try {
       super.stop();
     } catch (Exception ignore) {
     } finally {
       super.reset();
       closeSockets();
       if (mode == MODE_STREAMING) packetizer.stop();
       streaming = false;
     }
   }
 }
 @Override
 public void onError(MediaRecorder mr, int what, int extra) {
   // TODO Auto-generated method stub
   try {
     if (recorder != null) {
       recorder.reset();
       recorder = null;
     }
   } catch (IllegalStateException e) {
     Log.w("RecordView", "stopRecord", e);
   } catch (Exception e) {
     Log.w("RecordView", "stopRecord", e);
   }
 }
  public void toggleRecord(View v) {
    if (isRecording) {
      recorder.stop();
      recorder.reset();
      isRecording = false;

      try {
        FileInputStream f = new FileInputStream(tempFileName());

        player.setDataSource(f.getFD());
        player.prepare();
        player.start();
        Toast.makeText(v.getContext(), "Stopped!", Toast.LENGTH_SHORT).show();
      } catch (Exception e) {
        Toast.makeText(v.getContext(), e.getMessage(), Toast.LENGTH_LONG).show();
        player.reset();
      }
    } else {
      player.stop();
      player.reset();

      recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
      recorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
      recorder.setAudioEncoder(MediaRecorder.AudioEncoder.DEFAULT);
      recorder.setOutputFile(tempFileName());
      try {
        recorder.prepare();
        recorder.start();
        isRecording = true;
        Toast.makeText(v.getContext(), "Recording!", Toast.LENGTH_SHORT).show();
      } catch (Exception e) {
        Toast.makeText(v.getContext(), e.getMessage(), Toast.LENGTH_SHORT).show();
        recorder.stop();
        recorder.reset();
      }
    }
  }
  private void stopRecording() {
    System.out.println(cameraBusy + " " + recording);
    if (cameraBusy || !recording) return;
    System.out.println("stop - lock enabled");
    cameraBusy = true;
    recorder.stop();
    recorder.reset();
    recorder.release();
    mCamera.lock();
    stopCameraPreview();
    startCameraPreview();
    recording = false;
    cameraBusy = false;

    System.out.println("stop - lock disabled");
  }
Exemple #18
0
 private void releaseMediaRecorder() {
   if (mMediaRecorder != null) {
     try {
       mMediaRecorder.reset();
     } catch (Exception e) {
       e.printStackTrace();
     }
     try {
       mMediaRecorder.release();
     } catch (Exception e) {
       e.printStackTrace();
     }
     mMediaRecorder = null;
     mCamera.lock();
   }
 }
 private void stopRecording() {
   prMediaRecorder.stop();
   prMediaRecorder.reset();
   try {
     prCamera.reconnect();
   } catch (IOException e) {
     e.printStackTrace();
   }
   Toast.makeText(
           this.getApplicationContext(),
           "Video saved to " + mVideoFileFullPath,
           Toast.LENGTH_SHORT)
       .show();
   prStartBtn.setText("Start");
   prRecordInProcess = false;
   prCamera.startPreview();
 }
Exemple #20
0
  public void button2Click(View v) throws IOException, IllegalStateException {

    MediaRecorder recorder;
    recorder = new MediaRecorder();
    recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
    recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
    recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
    recorder.setOutputFile("/dev/null");
    try {
      recorder.prepare();
      Log.d(LOG_TAG, "RECORDER Ok ");
    } catch (IOException e) {
      Log.d(LOG_TAG, "Error WITH RECORDER " + e);
      e.printStackTrace();
    }
    recorder.start();
    Log.d(LOG_TAG, "Start ");
    for (int i = 0; i < 20; i++) {
      // System.err.println("current amplitude is:"+recorder.getMaxAmplitude());
      // System.err.println("current amplitude is:"+recorder.getMaxAmplitude());
      // textView1.setText("current MIC amplitude is:"+"_"+recorder.getMaxAmplitude());
      maxAmplitude = recorder.getMaxAmplitude();
      Log.d(LOG_TAG, "MaxAmplitude = " + maxAmplitude);
      if (maxAmplitude > 20000) {
        sp.play(soundCuckoo, 1, 1, 0, 1, 1);
        try {
          Thread.sleep(2000);
        } catch (Exception e) {
          Log.d(LOG_TAG, "Error " + e);
        }
      }

      try {
        Thread.sleep(1000);
      } catch (Exception e) {
        Log.d(LOG_TAG, "Error " + e);
      }
    }
    try {
      recorder.stop();
    } catch (Exception e) {
      Log.d(LOG_TAG, "Error " + e);
    }
    recorder.reset();
    recorder.release();
  }
  private void startRecording() {

    mMediaRecorder.reset();

    String fileName = UUID.randomUUID().toString().substring(0, 6).concat(".3gp");
    mFileName = Environment.getExternalStorageDirectory().getAbsolutePath() + "/" + fileName;

    mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
    mMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
    mMediaRecorder.setOutputFile(mFileName);
    mMediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);

    try {
      mMediaRecorder.prepare();
    } catch (IOException e) {
      e.printStackTrace();
    }

    mMediaRecorder.start();
  }
Exemple #22
0
  public boolean goonRecording() {
    if ((SoundRecorderService.STATE_PAUSE_RECORDING != mCurrentState) || (null == mRecorder)) {
      return false;
    }
    try {
      mRecorder.start();
    } catch (IllegalArgumentException exception) {
      LogUtils.e(TAG, "<goOnRecording> IllegalArgumentException");
      exception.printStackTrace();
      mRecorder.reset();
      mRecorder.release();
      mRecorder = null;
      mListener.onError(this, ErrorHandle.ERROR_RECORDING_FAILED);
      return false;
    }

    mSampleStart = SystemClock.elapsedRealtime();
    setState(SoundRecorderService.STATE_RECORDING);
    return true;
  }
  /** in case it is impossible to record */
  private void terminateAndEraseFile() {
    try {
      recorder.stop();
      recorder.reset();
      recorder.release();
      recorder = null;
      Toast toast =
          Toast.makeText(this, this.getString(R.string.receiver_end_call), Toast.LENGTH_SHORT);
      toast.show();
    } catch (IllegalStateException e) {
      e.printStackTrace();
    }
    File file = new File(myFileName);

    if (file.exists()) {
      file.delete();
    }
    Toast toast =
        Toast.makeText(this, this.getString(R.string.record_impossible), Toast.LENGTH_LONG);
    toast.show();
  }
Exemple #24
0
 public boolean stopRecording() {
   LogUtils.i(TAG, "<stopRecording> start");
   if (((SoundRecorderService.STATE_PAUSE_RECORDING != mCurrentState)
           && (SoundRecorderService.STATE_RECORDING != mCurrentState))
       || (null == mRecorder)) {
     LogUtils.i(TAG, "<stopRecording> end 1");
     mListener.onError(this, SoundRecorderService.STATE_ERROR_CODE);
     return false;
   }
   boolean isAdd = (SoundRecorderService.STATE_RECORDING == mCurrentState) ? true : false;
   synchronized (this) {
     try {
       if (mCurrentState != SoundRecorderService.STATE_IDLE) {
         mRecorder.stop();
       }
     } catch (RuntimeException exception) {
       /** M:modified for stop recording failed. @{ */
       handleException(false, exception);
       mListener.onError(this, ErrorHandle.ERROR_RECORDING_FAILED);
       LogUtils.e(TAG, "<stopRecording> recorder illegalstate exception in recorder.stop()");
     } finally {
       if (null != mRecorder) {
         mRecorder.reset();
         mRecorder.release();
         mRecorder = null;
       }
       if (isAdd) {
         mPreviousTime += SystemClock.elapsedRealtime() - mSampleStart;
       }
       mSampleLength = mPreviousTime;
       LogUtils.i(TAG, "<stopRecording> mSampleLength in ms is " + mPreviousTime);
       LogUtils.i(TAG, "<stopRecording> mSampleLength in s is = " + mSampleLength);
       setState(SoundRecorderService.STATE_IDLE);
     }
     /** @} */
   }
   LogUtils.i(TAG, "<stopRecording> end 2");
   return true;
 }
 public void startRecord() {
   mediaRecorder = new MediaRecorder();
   mediaRecorder.reset();
   mediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
   mediaRecorder.setAudioEncodingBitRate(96000);
   mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.DEFAULT);
   mediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
   mediaRecorder.setOutputFile(
       AppGlobals.getDataDirectory("CallRec")
           + "/"
           + AppGlobals.sCurrentNumber
           + "_"
           + Helpers.getTimeStamp()
           + ".aac");
   try {
     mediaRecorder.prepare();
   } catch (IOException e) {
     e.printStackTrace();
   }
   mediaRecorder.start();
   Log.i(AppGlobals.getLogTag(getClass()), "Recording started.....");
   isRecording = true;
 }
Exemple #26
0
 /**
  * 开始录音
  *
  * @version 1.0
  * @author zyh
  * @param chatId 会话Id
  */
 public void startRecording(String chatId) {
   if (recoder == null) {
     recoder = new MediaRecorder();
     recoder.setAudioSource(1);
     recoder.setOutputFormat(3);
     recoder.setAudioEncoder(1);
     recoder.setAudioChannels(1);
     recoder.setAudioEncodingBitRate(12200);
     recoder.setOnErrorListener(new RecorderErrorListener());
   } else {
     recoder.stop();
     recoder.reset();
   }
   recordFileName = System.currentTimeMillis() + ".amr";
   recordFilePath = getRecordFilePath(chatId);
   file = new File(recordFilePath);
   recoder.setOutputFile(file.getAbsolutePath());
   try {
     recoder.prepare();
     recoder.start();
     atomicBoolean.set(true);
     startTime = new Date().getTime();
     executor.execute(new CalculateRunnable(this));
     return;
   } catch (IllegalStateException localIllegalStateException) {
     Log.i("voice", "IllegalStateException thrown while trying to record a greeting");
     atomicBoolean.set(false);
     recoder.release();
     recoder = null;
     return;
   } catch (IOException localIOException) {
     Log.i("voice", "IOException thrown while trying to record a greeting");
     atomicBoolean.set(false);
     recoder.release();
     recoder = null;
   }
 }
  @Override
  public int onStartCommand(Intent intent, int flags, int startId) {
    int commandType = intent.getIntExtra("commandType", STATE_INCOMING_NUMBER);

    if (commandType == STATE_INCOMING_NUMBER) {
      if (phoneNumber == null) phoneNumber = intent.getStringExtra("phoneNumber");
    } else if (commandType == STATE_CALL_START) {

      /*try {
          Intent intentCall = new Intent(Intent.ACTION_CALL);
          //Intent intentCall = new Intent(Intent.ACTION_DIAL);
          intentCall.setData(Uri.parse("tel:0414-5458521"));
          intentCall.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
          intentCall.addFlags(Intent.FLAG_FROM_BACKGROUND);
          startActivity(intentCall);
      } catch (Exception e) {
          e.printStackTrace();
      }*/

      if (phoneNumber == null) phoneNumber = intent.getStringExtra("phoneNumber");

      try {
        // recorder.setAudioSource(MediaRecorder.AudioSource.VOICE_CALL);  // Original (This should
        // be the selected option, but returns error on Nexus5) (E/MediaRecorder: start failed:
        // -2147483648)
        recorder.setAudioSource(MediaRecorder.AudioSource.VOICE_COMMUNICATION);
        recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP); // Original
        // recorder.setOutputFormat(MediaRecorder.OutputFormat.AMR_NB);
        recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB); // Original
        // recorder.setAudioEncoder(MediaRecorder.AudioEncoder.DEFAULT);
        myFileName = getFilename();
        recorder.setOutputFile(myFileName);
      } catch (IllegalStateException e) {
        // Log.e("Call recorder IllegalStateException: ", "");
        terminateAndEraseFile();
        ExceptionUtils.printExceptionToFile(e);
      } catch (Exception e) {
        // Log.e("Call recorder Exception: ", "");
        terminateAndEraseFile();
        ExceptionUtils.printExceptionToFile(e);
      }

      /*OnErrorListener errorListener = new OnErrorListener() {

          public void onError(MediaRecorder arg0, int arg1, int arg2) {
              //Log.e("Call recorder OnErrorListener: ", arg1 + "," + arg2);
              arg0.stop();
              arg0.reset();
              arg0.release();
              arg0 = null;
              terminateAndEraseFile();
          }

      };
      recorder.setOnErrorListener(errorListener);
      OnInfoListener infoListener = new OnInfoListener() {

          public void onInfo(MediaRecorder arg0, int arg1, int arg2) {
              //Log.e("Call recorder OnInfoListener: ", arg1 + "," + arg2);
              arg0.stop();
              arg0.reset();
              arg0.release();
              arg0 = null;
              terminateAndEraseFile();
          }

      };
      recorder.setOnInfoListener(infoListener);*/

      try {
        recorder.prepare();
      } catch (IllegalStateException e) {
        // Log.e("Call recorder IllegalStateException: ", "");
        terminateAndEraseFile();
        e.printStackTrace();
        ExceptionUtils.printExceptionToFile(e);
      } catch (IOException e) {
        // Log.e("Call recorder IOException: ", "");
        terminateAndEraseFile();
        e.printStackTrace();
        ExceptionUtils.printExceptionToFile(e);
      } catch (Exception e) {
        // Log.e("Call recorder Exception: ", "");
        terminateAndEraseFile();
        e.printStackTrace();
        ExceptionUtils.printExceptionToFile(e);
      }

      try {
        recorder
            .start(); // TODO Check sometimes gives a problem here (This is beacause recorder
                      // parameters setAudioSource, OutputFormat and AudioEncoder)
        recordstarted = true;
        Toast.makeText(this, this.getString(R.string.receiver_start_call), Toast.LENGTH_LONG)
            .show();
      } catch (IllegalStateException e) {
        e.printStackTrace();
        ExceptionUtils.printExceptionToFile(e);
      }
    } else if (commandType == STATE_CALL_END) {
      try {
        if (recordstarted) {
          recorder.stop();
          recorder.reset();
          recorder.release();
          recordstarted = false;
          //
          Toast toast =
              Toast.makeText(this, this.getString(R.string.receiver_end_call), Toast.LENGTH_SHORT);
          toast.show();
          Firebase.setAndroidContext(this);
          new Firebase(CONSTANTS.FIREBASE_APP_URL + "RecordedAudiosByUser/CarlosJesusGH")
              .push()
              .child("AudioId")
              .setValue(myFileName);

          // Show notification
          Date now = new Date();
          int mNotificationId =
              (int)
                  now
                      .getTime(); // use date to generate an unique id to differentiate the
                                  // notifications.
          MessageUtils.notification(
              this,
              this.getString(R.string.notification_new_audio_recorded),
              myFileName,
              mNotificationId,
              RecordingLogActivity.class,
              new ArrayList<NotificationCompat.Action>(),
              false,
              null,
              true);
        }
        recorder = null;
        wasRinging = false;
      } catch (IllegalStateException e) {
        e.printStackTrace();
        ExceptionUtils.displayExceptionMessage(this, e);
        ExceptionUtils.printExceptionToFile(e);
      }

      try {
        if (manger != null) manger.cancel(0);
        stopForeground(true);
        this.stopSelf();
      } catch (Exception e) {
        ExceptionUtils.displayExceptionMessage(this, e);
        ExceptionUtils.printExceptionToFile(e);
      }
    }

    return super.onStartCommand(intent, flags, startId);
  }