示例#1
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);
 }
示例#2
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);
  }
示例#3
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, "서비스를  죽임");

  }
  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;
  }
示例#6
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();
 }
示例#7
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();
    }
  }
示例#8
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();
   }
 }
  /** 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;
  }
示例#10
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);
    }
  }
  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;
  }
示例#13
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();
  }
示例#14
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 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();
  }
示例#16
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();
  }
示例#17
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;
      }
    }
  }
 /**
  * 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);
   }
 }
示例#19
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();
  }
  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);
  }
示例#21
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);
     }
   }
 }
  /**
   * 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;
    }
  }
示例#23
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);
  }
示例#24
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();
  }
示例#25
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);
  }
示例#26
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;
  }
示例#27
0
  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();
  }
  private void createMediaRecord() {
    /* ①Initial:实例化MediaRecorder对象 */
    mMediaRecorder = new MediaRecorder();

    /* setAudioSource/setVedioSource */
    mMediaRecorder.setAudioSource(PMAudioFileFunc.AUDIO_INPUT); // 设置麦克风
    /*
     * 设置输出文件的格式:THREE_GPP/MPEG-4/RAW_AMR/Default
     * THREE_GPP(3gp格式,H263视频/ARM音频编码)、MPEG-4、RAW_AMR(只支持音频且音频编码要求为AMR_NB)
     */
    mMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.DEFAULT);

    /* 设置音频文件的编码:AAC/AMR_NB/AMR_MB/Default */
    mMediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.DEFAULT);
    /* 设置输出文件的路径 */
    File file = new File(PMAudioFileFunc.getAMRFilePath());
    if (file.exists()) {
      file.delete();
    }
    mMediaRecorder.setOutputFile(PMAudioFileFunc.getAMRFilePath());
  }
 /**
  * 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();
       filePath = null; // Reset file path
       cAmplitude = 0; // Reset amplitude
       if (rUncompressed) {
         audioRecorder = new AudioRecord(aSource, sRate, nChannels + 1, aFormat, bufferSize);
       } else {
         mediaRecorder = new MediaRecorder();
         mediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
         mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
         mediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
       }
       state = State.INITIALIZING;
     }
   } catch (Exception e) {
     Log.e(ExtAudioRecorder.class.getName(), e.getMessage());
     state = State.ERROR;
   }
 }
示例#30
0
 private void test07RecordAudio() {
   try {
     if (mButtons[TEST_07_RECORD].getText().equals(getString(R.string.cta_test_stop_record))) {
       Log.i(TAG, "test07RecordAudio call MediaRecorder.stop()");
       mRecorder.stop();
     } else {
       Log.i(TAG, "test07RecordAudio call MediaRecorder.start()");
       mRecorder = new MediaRecorder();
       mRecorder.setAudioSource(MediaRecorder.AudioSource.DEFAULT);
       mRecorder.setOutputFormat(MediaRecorder.OutputFormat.DEFAULT);
       mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.DEFAULT);
       mRecorder.setOutputFile("/sdcard/cta_test_audio_record.3gpp");
       mRecorder.prepare();
       mRecorder.start();
     }
   } catch (IllegalStateException e) {
     Log.i(TAG, "test07RecordAudio IllegalStateException");
   } catch (IOException e) {
     Log.i(TAG, "test07RecordAudio IOException");
   }
 }