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, "서비스를  죽임");

  }
 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
  // 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. 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;
  }
Esempio n. 6
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. 7
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;
    }
  }
Esempio n. 8
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();
  }
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;
  }
        @Override
        public void onClick(View v) {
          recorder = new MediaRecorder();
          String out = new SimpleDateFormat("dd-MM-yyyy hh-mm-ss").format(new Date());
          File sampleDir = new File(Environment.getExternalStorageDirectory(), "/TestData");
          if (!sampleDir.exists()) {
            sampleDir.mkdirs();
          }

          String file_name = "Record";
          try {
            if (spinType == "mp3") path = File.createTempFile(file_name + out, ".mp3", sampleDir);
            else path = File.createTempFile(file_name + out, ".wav", sampleDir);

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

          // path=new File(Environment.getExternalStorageDirectory(),"myRecording.3gpp");
          resetRecorder();
          try {
            recorder.start();
            Toast.makeText(MainActivity.this, "Start Record", Toast.LENGTH_SHORT).show();
            start.setEnabled(false);
            stop.setEnabled(true);
          } catch (Exception e) {
            e.printStackTrace();
          }
        }
Esempio n. 12
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();
    }
  }
 public boolean startRecording() {
   if (mediaRecorder == null) {
     if (!initRecorder()) return false;
   }
   mediaRecorder.setOnInfoListener(this);
   mediaRecorder.setOnErrorListener(this);
   mediaRecorder.start();
   return true;
 }
Esempio n. 14
0
  public void mediaControls(View view) {
    switch (view.getId()) {
      case R.id.recordbutton:
        // TODO Auto-generated method stub
        if (recording) {
          mediaRecorder.stop();
          releaseMediaRecorder();
          camerabtn.setBackgroundDrawable(
              getResources().getDrawable(R.drawable.button_notrecording));

          SavePreferences("customVideoPath", customVideoPath.toString());
          SavePreferences("MEDIA_TYPE", "5");
          Intent intent = new Intent(media_Video.this, categories_Writemessage.class);
          startActivity(intent);
          finish();

        } else {
          releaseCamera();
          if (!prepareMediaRecorder()) {
            finish();
          }
          try {
            mediaRecorder.start();
            doInBackground();
            gotimer();
          } catch (Exception e) {
            e.printStackTrace();
          }
          camerabtn.setBackgroundDrawable(
              getResources().getDrawable(R.drawable.button_isrecording));
          recording = true;
        }
        break;

      case R.id.flashbutton:
        if (!flashLight) {
          flashLight = true;
          flashbtn.setBackgroundDrawable(getResources().getDrawable(R.drawable.camera_flash));
        } else {
          flashLight = false;
          flashbtn.setBackgroundDrawable(getResources().getDrawable(R.drawable.camera_flashoff));
        }
        break;

      case R.id.switchbtn:
        switchCameras();
        break;

      case R.id.backbtn:
        finish();
        if (isPLaying == true) {
          player.stop();
          isPLaying = false;
        }
        break;
    }
  }
Esempio n. 15
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);
    }
  }
 /** Starts the recording, and sets the state to RECORDING. Call after prepare(). */
 public void start() {
   if (state == State.READY) {
     mRecorder.start();
     state = State.RECORDING;
   } else {
     SurespotLog.w(MediaRecorderWrapper.class.getName(), "start() called on illegal state");
     state = State.ERROR;
   }
 }
Esempio n. 17
0
 @Override
 public void surfaceCreated(SurfaceHolder holder) {
   mediaRecorder.setPreviewDisplay(holder.getSurface());
   try {
     mediaRecorder.prepare();
     mediaRecorder.start();
   } catch (IOException e) {
     e.printStackTrace();
   }
 }
Esempio n. 18
0
  public void start() {
    if (prepareVideoRecorder()) {

      mMediaRecorder.start();
      captureButton.setText("Stop");
      isRecording = true;
    } else {
      releaseMediaRecorder();
    }
  }
Esempio n. 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();
  }
Esempio n. 20
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. 21
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;
   }
 }
 /** Starts the recording, and sets the state to RECORDING. Call after prepare(). */
 public void start() {
   if (state == State.READY) {
     if (rUncompressed) {
       payloadSize = 0;
       audioRecorder.startRecording();
       audioRecorder.read(buffer, 0, buffer.length);
     } else {
       mediaRecorder.start();
     }
     state = State.RECORDING;
   } else {
     Log.e(ExtAudioRecorder.class.getName(), "start() called on illegal state");
     state = State.ERROR;
   }
 }
Esempio n. 23
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. 24
0
 public void onClick(View v) {
   if (recording) {
     recorder.stop();
     // recorder.release();
     recording = false;
     Log.v(TAG, "Recording Stopped");
     // Let's initRecorder so we can record again
     initRecorder();
     prepareRecorder();
   } else {
     recording = true;
     recorder.start();
     Log.v(TAG, "Recording Started");
   }
 }
Esempio n. 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();
  }
Esempio n. 26
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);
  }
Esempio n. 28
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. 29
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);
     }
   }
 }
  /** 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;
  }