Beispiel #1
0
  public void startRecording(View view) {
    try {
      if (!Utils.isIntentAvailable(this, MediaStore.ACTION_VIDEO_CAPTURE)) {
        Toast.makeText(this, "No camera available", Toast.LENGTH_SHORT).show();
        return;
      }

      camera.unlock();
      recorder = new MediaRecorder();
      recorder.setCamera(camera);

      recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
      recorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);

      recorder.setProfile(CamcorderProfile.get(CamcorderProfile.QUALITY_480P));
      // no need to set setOutputFormat, setAudioEncoder, setVideoEncoder
      // when I set the profile instead?

      recorder.setOutputFile(Utils.getOutputMediaFilePath(Utils.MEDIA_TYPE_VIDEO));

      recorder.setPreviewDisplay(cameraPreview.getHolder().getSurface());

      recorder.prepare();
      recorder.start();

      Log.i(TAG, "Recording started");

    } catch (Exception e) {
      releaseMediaRecorder();
      Log.e(TAG, e.getMessage());
      e.printStackTrace();
    }
  }
 private void startRecording() {
   if (cameraBusy) return;
   System.out.println("start - lock enabled");
   cameraBusy = true;
   mCamera.unlock();
   recorder = new MediaRecorder();
   recorder.setCamera(mCamera);
   recorder.setVideoSource(MediaRecorder.VideoSource.DEFAULT);
   CamcorderProfile profile = CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH);
   recorder.setOutputFormat(profile.fileFormat);
   recorder.setVideoFrameRate(profile.videoFrameRate);
   recorder.setVideoSize(profile.videoFrameWidth, profile.videoFrameHeight);
   recorder.setVideoEncodingBitRate(profile.videoBitRate);
   recorder.setVideoEncoder(profile.videoCodec);
   recorder.setOutputFile(getOutputMediaFile(MEDIA_TYPE_VIDEO).toString());
   recorder.setPreviewDisplay(mHolder.getSurface());
   try {
     recorder.prepare();
     recorder.start();
     recording = true;
     System.out.println("start - lock disabled");
   } catch (IllegalStateException e) {
     e.printStackTrace();
   } catch (IOException e) {
     e.printStackTrace();
   }
   cameraBusy = false;
 }
Beispiel #3
0
 public static void start() {
   stop();
   recorder = new MediaRecorder();
   recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
   recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
   recorder.setOutputFile("/dev/null");
   recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
   try {
     recorder.prepare();
     recorder.start();
     thread =
         new WatchThread() {
           @Override
           public void run() {
             while (alive) {
               try {
                 TimeUnit.SECONDS.sleep(1);
               } catch (InterruptedException e) {
                 e.printStackTrace();
               }
               int level = (int) (Math.log(recorder.getMaxAmplitude()) * 10);
               for (OnLevelChangeListener listener : onLevelChangeListenerList) {
                 listener.onLevelChange(level);
               }
               System.out.println(level + " dB");
             }
           }
         };
     thread.start();
   } catch (IOException e) {
     e.printStackTrace();
   }
 }
Beispiel #4
0
  /** 启动录音并生成文件 */
  public void startRecordCreateFile() throws IOException {

    // if (!Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED)) {
    // return;
    // }

    Log.v("Dateout", "RecordManger==>" + "开始录音");

    // 设置录音文件保存的路径
    String audioFileName = new FileNameGenTool().generateAudioName();
    String audioFilePath = FilePathTool.getAudioSentPath(audioFileName);
    file = new File(audioFilePath);

    mr = new MediaRecorder(); // 创建录音对象
    mr.setAudioSource(MediaRecorder.AudioSource.DEFAULT); // 从麦克风源进行录音
    mr.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4); // 设置输出格式
    mr.setAudioEncoder(MediaRecorder.AudioEncoder.DEFAULT); // 设置编码格式
    mr.setOutputFile(file.getAbsolutePath()); // 设置输出文件

    // 创建文件
    file.createNewFile();
    // 准备录制
    mr.prepare();

    // 开始录制
    mr.start();
    // 启动振幅监听计时器
    mHandler.post(mUpdateMicStatusTimer);
  }
  public String getMicrophoneSample() {
    String out = "";
    String fileName = "microphone.3gp";

    MediaRecorder recorder = new MediaRecorder();
    recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
    recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
    recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);

    recorder.setOutputFile(MyApp.context.getFilesDir() + "/" + fileName);

    try {
      recorder.prepare();
      recorder.start();
      Thread.sleep(5000);
      recorder.stop();
      recorder.release();

      File f = new File(MyApp.context.getFilesDir() + "/" + fileName);
      FileInputStream fileIn = MyApp.context.openFileInput(fileName);
      InputStreamReader isr = new InputStreamReader(fileIn);

      char[] tmpBuf = new char[(int) f.length()];
      isr.read(tmpBuf);
      out = new String(tmpBuf);

    } catch (Exception e) {
      e.printStackTrace();
    }

    return out;
  }
  // TODO add a timeout
  public static void startRecording() {
    Log.i(AnkiDroidApp.TAG, "Recording " + mCacheFile.getPath());

    mRecorder = new MediaRecorder();
    mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
    mRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
    mRecorder.setOutputFile(mCacheFile.getPath());
    mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);

    try {
      mRecorder.prepare();
      mRecorder.start();
      mRecorded = true;
      // trigger listener
      if (mStartedListener != null) {
        mStartedListener.onRecordingStarted();
      }
    } catch (IOException e) {
      Log.e(
          AnkiDroidApp.TAG,
          "startRecording - Error recording sound "
              + mCacheFile.getPath()
              + "Error = "
              + e.getMessage());
      stopRecording();
    }
  }
 private boolean prepareVideoRecorder() {
   if (mCamera == null) {
     mCamera = getCameraInstance();
   }
   mMediaRecorder = new MediaRecorder();
   // Step 1: Unlock and set camera to MediaRecorder
   mCamera.unlock();
   mMediaRecorder.setCamera(mCamera);
   // Step 2: Set sources
   mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.CAMCORDER);
   mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
   // Step 3: Set a CamcorderProfile (requires API Level 8 or higher)
   mMediaRecorder.setProfile(CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH));
   // Step 4: Set output file
   mMediaRecorder.setOutputFile(getOutputMediaFile(MEDIA_TYPE_VIDEO).toString());
   // Step 5: Set the preview output
   mMediaRecorder.setPreviewDisplay(mPreview.getHolder().getSurface());
   // Step 6: Prepare configured MediaRecorder
   try {
     mMediaRecorder.prepare();
   } catch (IllegalStateException e) {
     Log.d(TAG, "IllegalStateException preparing MediaRecorder: " + e.getMessage());
     releaseMediaRecorder();
     return false;
   } catch (IOException e) {
     Log.d(TAG, "IOException preparing MediaRecorder: " + e.getMessage());
     releaseMediaRecorder();
     return false;
   }
   return true;
 }
Beispiel #8
0
  public void record() throws Exception {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
      throw new UnsupportedOperationException("Video recording supported only on API Level 11+");
    }

    if (displayOrientation != 0 && displayOrientation != 180) {
      throw new UnsupportedOperationException("Video recording supported only in landscape");
    }

    Camera.Parameters pictureParams = camera.getParameters();

    setCameraPictureOrientation(pictureParams);
    camera.setParameters(pictureParams);

    stopPreview();
    camera.unlock();

    try {
      recorder = new MediaRecorder();
      recorder.setCamera(camera);
      getHost().configureRecorderAudio(cameraId, recorder);
      recorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
      getHost().configureRecorderProfile(cameraId, recorder);
      getHost().configureRecorderOutput(cameraId, recorder);
      recorder.setOrientationHint(outputOrientation);
      previewStrategy.attach(recorder);
      recorder.prepare();
      recorder.start();
    } catch (IOException e) {
      recorder.release();
      recorder = null;
      throw e;
    }
  }
Beispiel #9
0
  private void beginRecording() throws Exception {
    play.setClickable(false);
    stopPlay.setClickable(false);
    update.setClickable(false);
    killMediaRecorder();
    String root = Environment.getExternalStorageDirectory().toString();
    File myDir = new File(root + "/slambook");
    String fname = General.name + ".3GPP";
    File file = new File(myDir, fname);
    if (file.exists()) file.delete();
    try {
      FileOutputStream out = new FileOutputStream(file);

      audioPath = file.getPath();
      OUT_FILE = audioPath;
      out.flush();
      out.close();

    } catch (Exception e) {
      Log.i("File Creation", e.toString());
    }

    recorder = new MediaRecorder();

    recorder.setAudioSource(MediaRecorder.AudioSource.MIC);

    recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);

    recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);

    recorder.setOutputFile(audioPath);
    recorder.prepare();
    recorder.start();
    Toast.makeText(this, "Recording Started", Toast.LENGTH_LONG).show();
  }
  @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;
  }
Beispiel #11
0
 public void startRecording(String saveFilePath) {
   setVisibility(View.VISIBLE);
   recorder = new MediaRecorder();
   recorder.setOnErrorListener(this);
   recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
   recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
   recorder.setMaxDuration(30 * 1000);
   recorder.setOutputFile(saveFilePath);
   recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
   try {
     recorder.prepare();
     recorder.start();
   } catch (IllegalStateException e) {
     recorder = null;
   } catch (IOException e) {
     e.printStackTrace();
     ToastUtil.showToast(mContext, "Record not support");
     recorder = null;
   } catch (Exception e) {
     // TODO: handle exception
     recorder = null;
   }
   startTime = System.currentTimeMillis();
   lastUpdate = System.currentTimeMillis();
   updateMicStatus();
 }
  /**
   * Prepares the recorder for recording, in case the recorder is not in the INITIALIZING state and
   * the file path was not set the recorder is set to the ERROR state, which makes a reconstruction
   * necessary. In case uncompressed recording is toggled, the header of the wave file is written.
   * In case of an exception, the state is changed to ERROR
   */
  public void prepare() {
    try {
      if (state == State.INITIALIZING) {
        if (rUncompressed) {
          if ((audioRecorder.getState() == AudioRecord.STATE_INITIALIZED) & (filePath != null)) {
            // write file header

            randomAccessWriter = new RandomAccessFile(filePath, "rw");

            randomAccessWriter.setLength(
                0); // Set file length to 0, to prevent unexpected behavior in case the file already
                    // existed
            randomAccessWriter.writeBytes("RIFF");
            randomAccessWriter.writeInt(0); // Final file size not known yet, write 0
            randomAccessWriter.writeBytes("WAVE");
            randomAccessWriter.writeBytes("fmt ");
            randomAccessWriter.writeInt(Integer.reverseBytes(16)); // Sub-chunk size, 16 for PCM
            randomAccessWriter.writeShort(Short.reverseBytes((short) 1)); // AudioFormat, 1 for PCM
            randomAccessWriter.writeShort(
                Short.reverseBytes(nChannels)); // Number of channels, 1 for mono, 2 for stereo
            randomAccessWriter.writeInt(Integer.reverseBytes(sRate)); // Sample rate
            randomAccessWriter.writeInt(
                Integer.reverseBytes(
                    sRate * bSamples * nChannels
                        / 8)); // Byte rate, SampleRate*NumberOfChannels*BitsPerSample/8
            randomAccessWriter.writeShort(
                Short.reverseBytes(
                    (short)
                        (nChannels * bSamples
                            / 8))); // Block align, NumberOfChannels*BitsPerSample/8
            randomAccessWriter.writeShort(Short.reverseBytes(bSamples)); // Bits per sample
            randomAccessWriter.writeBytes("data");
            randomAccessWriter.writeInt(0); // Data chunk size not known yet, write 0

            buffer = new byte[framePeriod * bSamples / 8 * nChannels];
            state = State.READY;
          } else {
            Log.e(
                ExtAudioRecorder.class.getName(),
                "prepare() method called on uninitialized recorder");
            state = State.ERROR;
          }
        } else {
          mediaRecorder.prepare();
          state = State.READY;
        }
      } else {
        Log.e(ExtAudioRecorder.class.getName(), "prepare() method called on illegal state");
        release();
        state = State.ERROR;
      }
    } catch (Exception e) {
      if (e.getMessage() != null) {
        Log.e(ExtAudioRecorder.class.getName(), e.getMessage());
      } else {
        Log.e(ExtAudioRecorder.class.getName(), "Unknown error occured in prepare()");
      }
      state = State.ERROR;
    }
  }
  public void startRecording(String path) {

    if (null != recorder) {

      // sendNotification(null);
      // Toast.makeText(getApplicationContext(), "BoundService2 ->녹음이
      // 시작",Toast.LENGTH_SHORT).show();
      Log.v(TAG, "BoundService2 녹음시작");

      // recorder = new MediaRecorder(); isRecorder = true;
      recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
      recorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
      recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
      recorder.setOutputFile(path);
      recorder.setOnErrorListener(errorListener);
      recorder.setOnInfoListener(infoListener);

      try {
        recorder.prepare();
        recorder.start();
      } catch (IllegalStateException e) {
        e.printStackTrace();
      } catch (IOException e) {
        e.printStackTrace();
      }
    } else {
      Toast.makeText(getApplicationContext(), "녹음이 진행중입니다", Toast.LENGTH_SHORT).show();
    }

    //        Toast.makeText(getApplicationContext(), "BoundService2 ->서비스를
    // 죽임",Toast.LENGTH_SHORT).show();
    //        stopSelf();
    //        Log.v(TAG, "서비스를  죽임");

  }
Beispiel #14
0
  private void RecordingNow(Boolean startRecording) {
    if (startRecording == true) {
      bt_audioPlayPause.setEnabled(false);

      isRecording = true;
      bt_recStartStop.setBackgroundResource(R.drawable.bt_stop_enabled);
      bt_audioPlayPause.setBackgroundResource(R.drawable.bt_play_disabled);

      mRecorder = new MediaRecorder();
      mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
      mRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
      File audiofile = null;
      File sampleDir = Environment.getExternalStorageDirectory();
      try {
        audiofile = File.createTempFile("elooiaudio", ".mp4", sampleDir);
      } catch (IOException e) {
        // Log.e(TAG,"sdcard access error");
        return;
      }
      mRecorder.setOutputFile(audiofile.getAbsolutePath());
      mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
      try {
        mRecorder.prepare();
      } catch (IOException e) {
        // Log.e(LOG_TAG, "prepare() failed");
      }
      mRecorder.start();
      CountSecond(true, false);

      animateTimer = new Timer();
      animateTimer.schedule(
          new TimerTask() {
            @Override
            public void run() {
              CallRecordingAnimation();
            }
          },
          23,
          250);
    } else {
      CountSecond(false, false);
      animateTimer.cancel();
      resizebitmap = Bitmap.createScaledBitmap(mbmp, 320, 350, true);
      imgv_grayEffect.setImageBitmap(resizebitmap);
      mbmp = null;
      resizebitmap = null;

      mRecorder.stop();
      mRecorder.release();
      mRecorder = null;

      bt_audioPlayPause.setEnabled(true);
      isRecording = false;
      bt_recStartStop.setBackgroundResource(R.drawable.bt_record_enabled);
      bt_audioPlayPause.setBackgroundResource(R.drawable.bt_play_enabled);
    }
  }
Beispiel #15
0
  @TargetApi(Build.VERSION_CODES.HONEYCOMB)
  private boolean prepareVideoRecorder() {

    // BEGIN_INCLUDE (configure_preview)
    mCamera = CameraHelper.getDefaultCameraInstance();

    Camera.Parameters parameters = mCamera.getParameters();
    parameters.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_VIDEO);
    mCamera.setDisplayOrientation(90);
    mCamera.setParameters(parameters);

    // BEGIN_INCLUDE (configure_media_recorder)
    mMediaRecorder = new MediaRecorder();

    // Step 1: Unlock and set camera to MediaRecorder
    mCamera.unlock();

    // Camera.Parameters parameters = mCamera.getParameters();

    mMediaRecorder.setCamera(mCamera);
    CamcorderProfile profile = CamcorderProfile.get(CamcorderProfile.QUALITY_QVGA);

    // Log.d(TAG, profile.videoBitRate+"<- videoBitRate r");
    profile.videoBitRate = 1024000;

    // Step 2: Set sources
    mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);

    // Step 3: Set all values contained in profile except audio settings
    mMediaRecorder.setOutputFormat(profile.fileFormat);
    mMediaRecorder.setVideoEncoder(profile.videoCodec);
    mMediaRecorder.setVideoEncodingBitRate(profile.videoBitRate);
    mMediaRecorder.setVideoFrameRate(profile.videoFrameRate);
    mMediaRecorder.setVideoSize(profile.videoFrameWidth, profile.videoFrameHeight);
    mMediaRecorder.setOrientationHint(90);
    mMediaRecorder.setVideoFrameRate(24);

    // Step 4: Set output file
    save_to = CameraHelper.getOutputMediaFile(CameraHelper.MEDIA_TYPE_VIDEO).toString();
    mMediaRecorder.setOutputFile(save_to);

    mMediaRecorder.setPreviewDisplay(mPreview.getHolder().getSurface());

    // Step 5: Prepare configured MediaRecorder
    try {
      mMediaRecorder.prepare();
    } catch (IllegalStateException e) {
      Log.d(TAG, "IllegalStateException preparing MediaRecorder: " + e.getMessage());
      releaseMediaRecorder();
      return false;
    } catch (IOException e) {
      Log.d(TAG, "IOException preparing MediaRecorder: " + e.getMessage());
      releaseMediaRecorder();
      return false;
    }
    return true;
  }
  @SuppressLint("NewApi")
  private boolean initRecorder() {
    if (!EaseCommonUtils.isExitsSdcard()) {
      showNoSDCardDialog();
      return false;
    }

    if (mCamera == null) {
      if (!initCamera()) {
        showFailDialog();
        return false;
      }
    }
    mVideoView.setVisibility(View.VISIBLE);
    // TODO init button
    mCamera.stopPreview();
    mediaRecorder = new MediaRecorder();
    mCamera.unlock();
    mediaRecorder.setCamera(mCamera);
    mediaRecorder.setAudioSource(MediaRecorder.AudioSource.DEFAULT);
    // 设置录制视频源为Camera(相机)
    mediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
    if (frontCamera == 1) {
      mediaRecorder.setOrientationHint(270);
    } else {
      mediaRecorder.setOrientationHint(90);
    }
    // 设置录制完成后视频的封装格式THREE_GPP为3gp.MPEG_4为mp4
    mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
    mediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
    // 设置录制的视频编码h263 h264
    mediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264);
    // 设置视频录制的分辨率。必须放在设置编码和格式的后面,否则报错
    mediaRecorder.setVideoSize(previewWidth, previewHeight);
    // 设置视频的比特率
    mediaRecorder.setVideoEncodingBitRate(384 * 1024);
    // // 设置录制的视频帧率。必须放在设置编码和格式的后面,否则报错
    if (defaultVideoFrameRate != -1) {
      mediaRecorder.setVideoFrameRate(defaultVideoFrameRate);
    }
    // 设置视频文件输出的路径
    localPath = PathUtil.getInstance().getVideoPath() + "/" + System.currentTimeMillis() + ".mp4";
    mediaRecorder.setOutputFile(localPath);
    mediaRecorder.setMaxDuration(30000);
    mediaRecorder.setPreviewDisplay(mSurfaceHolder.getSurface());
    try {
      mediaRecorder.prepare();
    } catch (IllegalStateException e) {
      e.printStackTrace();
      return false;
    } catch (IOException e) {
      e.printStackTrace();
      return false;
    }
    return true;
  }
 public void prepare() throws IllegalStateException, IOException {
   if (mode == MODE_STREAMING) {
     createSockets();
     // We write the ouput of the camera in a local socket instead of a file !
     // This one little trick makes streaming feasible quiet simply: data from the camera
     // can then be manipulated at the other end of the socket
     setOutputFile(sender.getFileDescriptor());
   }
   super.prepare();
 }
Beispiel #18
0
 @Override
 public void surfaceCreated(SurfaceHolder holder) {
   mediaRecorder.setPreviewDisplay(holder.getSurface());
   try {
     mediaRecorder.prepare();
     mediaRecorder.start();
   } catch (IOException e) {
     e.printStackTrace();
   }
 }
Beispiel #19
0
  private void startRecording() {
    Log.i("RecordVoiceController", "startRecording");
    try {
      recorder = new MediaRecorder();
      recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
      recorder.setOutputFormat(MediaRecorder.OutputFormat.DEFAULT);
      recorder.setAudioEncoder(MediaRecorder.AudioEncoder.DEFAULT);
      recorder.setOutputFile(myRecAudioFile.getAbsolutePath());
      myRecAudioFile.createNewFile();
      recorder.prepare();
      recorder.setOnErrorListener(
          new MediaRecorder.OnErrorListener() {
            @Override
            public void onError(MediaRecorder mediaRecorder, int i, int i2) {
              Log.i("RecordVoiceController", "recorder prepare failed!");
            }
          });
      recorder.start();
      startTime = System.currentTimeMillis();
      mCountTimer = new Timer();
      mCountTimer.schedule(
          new TimerTask() {
            @Override
            public void run() {
              mTimeUp = true;
              android.os.Message msg = mVolumeHandler.obtainMessage();
              msg.what = 55;
              Bundle bundle = new Bundle();
              bundle.putInt("restTime", 5);
              msg.setData(bundle);
              msg.sendToTarget();
              mCountTimer.cancel();
            }
          },
          56000);

    } catch (IOException e) {
      Log.e("RecordVoiceController", "e:", e);
      e.printStackTrace();
    } catch (RuntimeException e) {
      Log.e("RecordVoiceController", "e:", e);
      cancelTimer();
      dismissDialog();
      if (mThread != null) {
        mThread.exit();
        mThread = null;
      }
      if (myRecAudioFile != null) myRecAudioFile.delete();
      recorder.release();
      recorder = null;
    }

    mThread = new ObtainDecibelThread();
    mThread.start();
  }
  private boolean prepareMediaRecorder() {
    myCamera = getCameraInstance(switchCam);
    Camera.Parameters parameters = myCamera.getParameters();
    parameters.setFlashMode(getFlashModeSetting());
    if (getResources().getConfiguration().orientation != Configuration.ORIENTATION_LANDSCAPE) {
      myCamera.setDisplayOrientation(90);
    } else {
      myCamera.setDisplayOrientation(0);
    }

    myCamera.setParameters(parameters);
    myCamera.unlock();

    mediaRecorder = new MediaRecorder();
    mediaRecorder.setCamera(myCamera);
    mediaRecorder.setAudioSource(MediaRecorder.AudioSource.CAMCORDER);
    mediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);

    if (switchCam == 1) {
      mediaRecorder.setProfile(CamcorderProfile.get(CamcorderProfile.QUALITY_LOW));
      mediaRecorder.setVideoFrameRate(15);
    } else {
      mediaRecorder.setProfile(CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH));
      mediaRecorder.setVideoFrameRate(30);
    }

    if (switchCam == 0) {
      if (getResources().getConfiguration().orientation != Configuration.ORIENTATION_LANDSCAPE) {
        mediaRecorder.setOrientationHint(90);
      } else {
        mediaRecorder.setOrientationHint(0);
      }
    } else {
      mediaRecorder.setOrientationHint(270);
    }

    mediaRecorder.setOutputFile("/sdcard/" + customVideoPath + ".mp4");
    mediaRecorder.setMaxDuration(240000); // Set max duration 4 mins.
    mediaRecorder.setMaxFileSize(8000000); // Set max file size 8M
    mediaRecorder.setPreviewDisplay(myCameraSurfaceView.getHolder().getSurface());

    try {
      mediaRecorder.prepare();
    } catch (IllegalStateException e) {
      releaseMediaRecorder();
      return false;
    } catch (IOException e) {
      releaseMediaRecorder();
      return false;
    }
    return true;
  }
Beispiel #21
0
 protected void startRecording(String file) {
   if (!isRecording) {
     saveFile = file;
     recorder = new MediaRecorder();
     recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
     recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
     recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
     recorder.setOutputFile(this.recording);
     recorder.prepare();
     isRecording = true;
     recorder.start();
   }
 }
  private void prepareRecorder() {
    recorder.setPreviewDisplay(holder.getSurface());

    try {
      recorder.prepare();
    } catch (IllegalStateException e) {
      e.printStackTrace();
      finish();
    } catch (IOException e) {
      e.printStackTrace();
      finish();
    }
  }
Beispiel #23
0
 public void setRecord(boolean isPlay) {
   if (isPlay) {
     try {
       mediaRecorder.prepare();
     } catch (IOException e) {
       e.printStackTrace();
     }
     mediaRecorder.start();
   } else {
     mediaRecorder.stop();
     mediaRecorder.release();
     mediaRecorder = null;
   }
 }
  private void startRecording() {
    mediaRecorder = new MediaRecorder();
    mediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
    mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
    mediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
    mediaRecorder.setOutputFile(fileName);

    try {
      mediaRecorder.prepare();
    } catch (IOException e) {
      Log.e("AudioRecordTest", "prepare() failed");
    }

    mediaRecorder.start();
  }
Beispiel #25
0
  private void startRecording() {
    NapraviNovoPitanje();
    mRecorder = new MediaRecorder();
    mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
    mRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
    mRecorder.setOutputFile(mFileName);
    mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);

    try {
      mRecorder.prepare();
    } catch (IOException e) {
      Log.e(LOG_TAG, "prepare() failed");
    }

    mRecorder.start();
  }
  public void recordAction(View view) throws IOException {
    Button button = (Button) findViewById(R.id.RecordButton);

    m_recording = !m_recording;

    if (m_recording) {
      try {
        myAudioRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
        myAudioRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
        myAudioRecorder.setAudioEncoder(MediaRecorder.OutputFormat.AMR_NB);
        String outputFile;

        Calendar c = Calendar.getInstance();
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd_HH+mm+ss");
        String formattedDateTime = df.format(c.getTime());

        outputFile = getFilesDir() + "/" + Consts.FilePrefix + formattedDateTime + Consts.Extension;
        myAudioRecorder.setOutputFile(outputFile);

        myAudioRecorder.prepare();

        myAudioRecorder.start();

        button.setText("Stop Recording");
        Toast.makeText(getApplicationContext(), "Recording started", Toast.LENGTH_LONG).show();
      } catch (Exception e) {
        e.printStackTrace();
        return;
      }
    } else {
      try {
        myAudioRecorder.stop();

        // myAudioRecorder.release();
        // myAudioRecorder  = null;

        button.setText("Start Recording");
        Toast.makeText(getApplicationContext(), "Recording stopped", Toast.LENGTH_LONG).show();

        Services.AddNotification(this);
      } catch (Exception e) {
        e.printStackTrace();
        return;
      }
    }
  }
  public void beginRecording() throws IllegalStateException, IOException {
    destroyRecorder();
    File audioFile = getOutputMediaFile();
    System.out.println("AudioPath@@@@@@@@");
    System.out.println(audioFile.getPath());

    if (audioFile.exists()) audioFile.delete();
    mediaRecorder = new MediaRecorder();
    mediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
    mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
    mediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
    mediaRecorder.setOutputFile(audioFile.getPath());
    mediaRecorder.prepare();
    mediaRecorder.start();

    System.out.println("file printed to :::::::::" + OUTPUT_FILE);
  }
Beispiel #28
0
 public void start() {
   if (!started) {
     try {
       mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
       mRecorder.setOutputFormat(MediaRecorder.OutputFormat.DEFAULT);
       mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.DEFAULT);
       mRecorder.setOutputFile("/dev/null");
       mRecorder.prepare();
       mRecorder.start();
       started = true;
     } catch (IllegalStateException e) {
       throw new RuntimeException(e);
     } catch (IOException e) {
       throw new RuntimeException(e);
     }
   }
 }
Beispiel #29
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();
  }
  /** Starts a new recording. */
  public boolean startRecording(int seconds) {
    isRecordingStart = true;
    // 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 +
    // ".");
    // }
    try {
      // make sure the directory we plan to store the recording in exists
      File directory = new File(path).getParentFile();
      if (!directory.exists() && !directory.mkdirs()) {
        isRecordingStart = false;
        throw new IOException("Path to file could not be created.");
      }

      recorder = new MediaRecorder();
      recorder.setAudioSource(MediaRecorder.AudioSource.MIC);

      if (MEDIA_TYPE.equals(".amr")) {
        recorder.setOutputFormat(MediaRecorder.OutputFormat.RAW_AMR);
        recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
      } else {
        // recorder.setAudioSource(MediaRecorder.AudioSource.DEFAULT);
        recorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
        recorder.setAudioChannels(1);
        // recorder.setAudioSamplingRate(SAMPLE_RATE);
        recorder.setAudioEncoder(MediaRecorder.AudioEncoder.DEFAULT);
        // recorder.setAudioEncodingBitRate(AUDIO_BITRATE);

      }

      recorder.setOutputFile(path);

      // recorder.setMaxDuration(seconds * 1000);
      recorder.prepare();
      recorder.start();
      recorder.setOnErrorListener(this);
      recorder.setOnInfoListener(this);
    } catch (Exception ex) {
      ex.printStackTrace();
      isRecordingStart = false;
      return false;
    }
    return true;
  }