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;
  }
 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;
 }
Esempio n. 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();
   }
 }
Esempio n. 4
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();
  }
  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, "서비스를  죽임");

  }
Esempio n. 6
0
  // 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();
    }
  }
Esempio n. 7
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);
  }
Esempio n. 8
0
 private void initiateMediaRecorder() {
   mediaRecorder = new MediaRecorder();
   mediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
   mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
   mediaRecorder.setOutputFile(setFileName());
   mediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
 }
Esempio n. 9
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();
 }
  @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;
  }
  /** 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;
  }
Esempio n. 12
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);
    }
  }
Esempio n. 13
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;
  }
  private void resetRecorder() {

    recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
    if (spinType == "mp3") {
      recorder.setOutputFormat(MediaRecorder.OutputFormat.DEFAULT);
      recorder.setAudioEncoder(MediaRecorder.AudioEncoder.DEFAULT);
    } else {
      recorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
      recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
    }
    recorder.setAudioEncodingBitRate(quality);
    recorder.setOutputFile(path.getAbsolutePath());
    try {
      recorder.prepare();
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
  @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;
  }
Esempio n. 16
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();
  }
Esempio n. 17
0
  private void configureMediaRecorder() {
    mediaRecorder.setCamera(camera);
    mediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);

    mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);

    mediaRecorder.setVideoSize(1280, 720);
    mediaRecorder.setVideoEncodingBitRate(17000000);
    mediaRecorder.setVideoFrameRate(30);

    mediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H263);
  }
Esempio n. 18
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();
   }
 }
Esempio n. 19
0
  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();
  }
Esempio n. 20
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();
  }
Esempio n. 21
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();
  }
Esempio n. 22
0
  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);
  }
 /**
  * Uses the settings from a CamcorderProfile object for recording. This method should be called
  * after the video AND audio sources are set, and before setOutputFile(). If a time lapse
  * CamcorderProfile is used, audio related source or recording parameters are ignored.
  *
  * @param profile the CamcorderProfile to use
  * @see android.media.CamcorderProfile
  */
 public void setProfile(CamcorderProfile profile) {
   setOutputFormat(profile.fileFormat);
   setVideoFrameRate(profile.videoFrameRate);
   setVideoSize(profile.videoFrameWidth, profile.videoFrameHeight);
   setVideoEncodingBitRate(profile.videoBitRate);
   setVideoEncoder(profile.videoCodec);
   if (profile.quality >= CamcorderProfile.QUALITY_TIME_LAPSE_LOW
       && profile.quality <= CamcorderProfile.QUALITY_TIME_LAPSE_QVGA) {
     // Nothing needs to be done. Call to setCaptureRate() enables
     // time lapse video recording.
   } else {
     setAudioEncodingBitRate(profile.audioBitRate);
     setAudioChannels(profile.audioChannels);
     setAudioSamplingRate(profile.audioSampleRate);
     setAudioEncoder(profile.audioCodec);
   }
 }
Esempio n. 25
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);
     }
   }
 }
Esempio n. 26
0
  @Override
  public void start(String audioFileName) {
    isRecord = true;
    mediaRecorder = new MediaRecorder();
    mediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
    mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.DEFAULT);
    mediaRecorder.setOutputFile(audioFileName);
    mediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
    try {
      mediaRecorder.prepare();
    } catch (IOException e) {
      Log.e(LOG_TAG, "prepare() failed");
    }

    mediaRecorder.start();
    recordButton.setText("Stop");
    recordButton.postDelayed(recordAnim, 1000);
  }
  /**
   * Resets the recorder to the INITIALIZING state, as if it was just created. In case the class was
   * in RECORDING state, the recording is stopped. In case of exceptions the class is set to the
   * ERROR state.
   */
  public void reset() {
    try {
      if (state != State.ERROR) {
        release();
        fPath = null; // Reset file path

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

        state = State.INITIALIZING;
      }
    } catch (Exception e) {
      SurespotLog.e(MediaRecorderWrapper.class.getName(), e, e.getMessage());
      state = State.ERROR;
    }
  }
Esempio n. 28
0
  /**
   * 录音
   *
   * @author shicong
   */
  private void startRecording(File aFile) {
    MediaRecorder sRecorder = new MediaRecorder();
    sRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
    sRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
    sRecorder.setOutputFile(aFile.getAbsolutePath());
    sRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
    sRecorder.setMaxDuration(mRecord_Max_Time);
    try {
      sRecorder.prepare();
    } catch (IOException e) {
      Debug.d(TAG, "Start record error...", DEBUG);
      UtilSystem.SystemToast(mContext, "录音失败!~~");
      return;
    }

    /*数据监控*/
    mVolumeMonitorTask = new VolumeMonitor();
    mVolumeMonitorTask.execute(sRecorder);
  }
Esempio n. 29
0
  private boolean prepareVideoRecorder() {
    mMediaRecorder = new MediaRecorder();

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

    // Step 2: Set sources
    mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.DEFAULT);
    mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.DEFAULT);

    // Step 3: Set a CamcorderProfile (requires API Level 8 or higher)
    // mMediaRecorder.setProfile(CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH));

    // Step 3: Set output format and encoding (for versions prior to API Level 8)
    mMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
    mMediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.DEFAULT);
    mMediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H263);

    // Step 4: Set output file
    mMediaRecorder.setOutputFile(ls.getFileDescriptor());

    // Step 5: Set the preview output
    // mMediaRecorder.setPreviewDisplay(mPreview.getHolder().getSurface());
    mMediaRecorder.setPreviewDisplay(holder.getSurface());

    Log.i(TAG, "Surface valid: " + holder.getSurface().isValid());

    /*mMediaRecorder.setVideoSize(176, 144);
    mMediaRecorder.setVideoFrameRate(20);
    mMediaRecorder.setAudioChannels(1);
    */

    // Step 6: Prepare configured MediaRecorder
    try {
      mMediaRecorder.prepare();
    } catch (Exception e) {
      Log.d(TAG, "Exception preparing MediaRecorder: " + e.getMessage());
      releaseMediaRecorder();
      return false;
    }
    return true;
  }
Esempio n. 30
0
  /** Starts a new recording. */
  public void start() throws IOException {
    recorder = new MediaRecorder();
    //	    String state = android.os.Environment.getExternalStorageState();

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

    File file =
        new File(
            UsbongUtils.BASE_FILE_PATH
                + UsbongUtils.getDateTimeStamp()
                + "/"
                + myRecordAudioFileName
                + ".3gp");
    path = file.getPath();

    // check if memory card is being used
    // UNCOMMENT BELOW TO PERFORM MEMORY CARD SAVING
    /*
           	if(!state.equals(android.os.Environment.MEDIA_MOUNTED))
    	    {
    	    	// instead save on the data directory
    //	    	File file = new File(Environment.getDataDirectory().getAbsolutePath()+
    //	    			"/data/edu.ateneo.android/test.3gp");

    	        recorder.setOutputFile(path);
    	  	}
    	    else
    	    {
    */
    // 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.setOutputFile(path);
    //	    }
    // UNCOMMENT ABOVE TO PERFORM MEMORY CARD SAVING
    recorder.prepare();
    recorder.start();
  }