android.media.MediaRecorder.release()方法的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(10.3k)|赞(0)|评价(0)|浏览(201)

本文整理了Java中android.media.MediaRecorder.release()方法的一些代码示例,展示了MediaRecorder.release()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。MediaRecorder.release()方法的具体详情如下:
包路径:android.media.MediaRecorder
类名称:MediaRecorder
方法名:release

MediaRecorder.release介绍

暂无

代码示例

代码示例来源:origin: stackoverflow.com

mRecorder = new MediaRecorder();
mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
mRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
mRecorder.setOutputFile("/dev/null"); 
mRecorder.prepare();
mRecorder.start();
mRecorder.stop();       
mRecorder.release();
mRecorder = null;

代码示例来源:origin: stackoverflow.com

MediaRecorder mRecorder = new MediaRecorder();
File mFile = new File("The output file's absolutePath");

... //config the mRecorder
mRecorder.setOutputFile(mFile.getAbsolutePath());

... //prepare() ...
mRecorder.start();

try {
  mRecorder.stop();
} catch(RuntimeException e) {
  mFile.delete();  //you must delete the outputfile when the recorder stop failed.
} finally {
  mRecorder.release();
  mRecorder = null;
}

代码示例来源:origin: stackoverflow.com

// need to make recorder final so it can be referenced from anonymous Runnable
final MediaRecorder recorder = new MediaRecorder();
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
recorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
recorder.setOutputFile(path);
recorder.prepare();
recorder.start();
postDelayed(new Runnable() {
  @Override
  public void run() {
    recorder.stop();
    recorder.reset();
    recorder.release();
  }
}, 40000);

代码示例来源:origin: guardianproject/haven

final MediaRecorder recorder = new MediaRecorder();
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
recorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
recorder.setOutputFile(audioPath.toString());
try {
 recorder.prepare();
} catch (Exception e){
  e.printStackTrace();
  recorder.start();
  try {
    Thread.sleep(prefs.getAudioLength());
  recorder.stop();
  Log.i("AudioRecorderTask", "Stopped recording");
  recorder.release();

代码示例来源:origin: stackoverflow.com

MediaRecorder mRecorder = new MediaRecorder();
File mFile = new File("The output file's absolutePath");

... //config the mRecorder
mRecorder.setOutputFile(mFile.getAbsolutePath());

... //prepare() ...
mRecorder.start();

try {
  mRecorder.stop();
} catch(RuntimeException e) {
  mFile.delete();  //you must delete the outputfile when the recorder stop failed.
} finally {
  mRecorder.release();
  mRecorder = null;
}

代码示例来源:origin: LLhon/Android-Video-Editor

mediaRecorder.setPreviewDisplay(null);
try {
  mediaRecorder.stop();
} catch (RuntimeException e) {
  e.printStackTrace();
  mediaRecorder = null;
  mediaRecorder = new MediaRecorder();
} finally {
  if (mediaRecorder != null) {
    mediaRecorder.release();

代码示例来源:origin: stackoverflow.com

String message = e.getMessage();
    Log.i(null, "Problem Start"+message);
    mrec.release();
  mrec.stop();
  mrec.release();
  mrec = null;
  break;
mrec = new MediaRecorder();  // Works well
mCamera.unlock();
mrec.setAudioSource(MediaRecorder.AudioSource.MIC); 
mrec.setOutputFile("/sdcard/zzzz.3gp"); 
mrec.prepare();
mrec.start();
mrec.stop();
mrec.release();
mCamera.release();
if (mrec != null) {
  mrec.release(); // release the recorder object
  mrec = null;

代码示例来源:origin: stackoverflow.com

public class Call extends BroadcastReceiver{       
   private MediaRecorder mRecorder;
   public void onReceive(Context context, Intent intent){           
    //...
    if(state.equalsIgnoreCase(TelephonyManager.EXTRA_STATE_RINGING)){
      mRecorder = new MediaRecorder();
      mRecorder.start();
      //....
    }
    if(state.equalsIgnoreCase(TelephonyManager.EXTRA_STATE_IDLE)){
      if(mRecorder!=null){
        mRecorder.stop();
        mRecorder.release();
        mRecorder = null;
      }
    }
  }
}

代码示例来源:origin: stackoverflow.com

setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
recorder = new MediaRecorder();
initRecorder();
setContentView(R.layout.main);
recorder.setAudioSource(MediaRecorder.AudioSource.DEFAULT);
recorder.setVideoSource(MediaRecorder.VideoSource.DEFAULT);
  recorder.prepare();
} catch (IllegalStateException e) {
  e.printStackTrace();
  recorder.stop();
  recording = false;
} else {
  recording = true;
  recorder.start();
  recorder.stop();
  recording = false;
recorder.release();
finish();

代码示例来源:origin: stackoverflow.com

mediaRecorder = new MediaRecorder();
  camera.unlock();
  mediaRecorder.setAudioSource(MediaRecorder.AudioSource.CAMCORDER);
  mediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
  mediaRecorder.setProfile(CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH));
  mediaRecorder.setOutputFile(
      Environment.getExternalStorageDirectory()+"/"+
      DateFormat.format("yyyy-MM-dd_kk-mm-ss", new Date().getTime())+
  );
  try { mediaRecorder.prepare(); } catch (Exception e) {}
  mediaRecorder.start();
public void onDestroy() {
  mediaRecorder.stop();
  mediaRecorder.reset();
  mediaRecorder.release();

代码示例来源:origin: stackoverflow.com

recorder = new MediaRecorder();
  recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
  recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
  recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
  recorder.setOutputFile(audioDirTemp + "/audio_file"
      + ".mp3");
    recorder.prepare();
    recorder.start();
    isRecording = true; // we are currently recording
  } catch (IllegalStateException e) {
handler.removeCallbacks(updateVisualizer);
visualizerView.clear();
recorder.stop();
recorder.reset();
recorder.release();
recorder = null;

代码示例来源:origin: stackoverflow.com

} else
  mediaRecorder = new MediaRecorder();
  mediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
  mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
  mediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);                
  if (!rUncompressed)
    mediaRecorder.setOutputFile(filePath);                    
    mediaRecorder.prepare();
    state = State.READY;
  mediaRecorder.release();
    mediaRecorder = new MediaRecorder();
    mediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
    mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
    mediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
  mediaRecorder.start();
  mediaRecorder.stop();

代码示例来源:origin: Piasy/RxAndroidAudio

stopRecord();
mRecorder = new MediaRecorder();
mRecorder.setAudioSource(audioSource);
mRecorder.setOutputFormat(outputFormat);
mRecorder.setAudioSamplingRate(sampleRate);
mRecorder.setAudioEncodingBitRate(bitRate);
mRecorder.setAudioEncoder(audioEncoder);
mRecorder.setOutputFile(outputFile.getAbsolutePath());
  mRecorder.prepare();
} catch (IOException | RuntimeException exception) {
  Log.w(TAG, "startRecord fail, prepare fail: " + exception.getMessage());
  setError(ERROR_INTERNAL);
  mRecorder.reset();
  mRecorder.release();
  mRecorder = null;
  return false;
  mRecorder.start();
  mStarted = true;
} catch (RuntimeException exception) {
  setError(ERROR_INTERNAL);
  mRecorder.reset();
  mRecorder.release();
  mRecorder = null;
  mStarted = false;

代码示例来源:origin: Piasy/RxAndroidAudio

/**
 * prepare for a new audio record.
 */
@WorkerThread
public synchronized boolean prepareRecord(int audioSource, int outputFormat, int audioEncoder,
    int sampleRate, int bitRate, File outputFile) {
  stopRecord();
  mRecorder = new MediaRecorder();
  mRecorder.setAudioSource(audioSource);
  mRecorder.setOutputFormat(outputFormat);
  mRecorder.setAudioSamplingRate(sampleRate);
  mRecorder.setAudioEncodingBitRate(bitRate);
  mRecorder.setAudioEncoder(audioEncoder);
  mRecorder.setOutputFile(outputFile.getAbsolutePath());
  // Handle IOException
  try {
    mRecorder.prepare();
  } catch (IOException exception) {
    Log.w(TAG, "startRecord fail, prepare fail: " + exception.getMessage());
    setError(ERROR_INTERNAL);
    mRecorder.reset();
    mRecorder.release();
    mRecorder = null;
    return false;
  }
  mState = STATE_PREPARED;
  return true;
}

代码示例来源:origin: stackoverflow.com

recorder = new MediaRecorder();
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
recorder.setOutputFormat(output_formats[currentFormat]);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
recorder.setOutputFile(getFilename());
recorder.setOnErrorListener(errorListener);
recorder.setOnInfoListener(infoListener);
  recorder.prepare();
  recorder.start();
} catch (IllegalStateException e) {
  e.printStackTrace();
  recorder.stop();
  recorder.reset();
  recorder.release();

代码示例来源:origin: stackoverflow.com

setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
recorder = new MediaRecorder();
initRecorder();
setContentView(R.layout.main);
recorder.setAudioSource(MediaRecorder.AudioSource.DEFAULT);
recorder.setVideoSource(MediaRecorder.VideoSource.DEFAULT);
  recorder.prepare();
} catch (IllegalStateException e) {
  e.printStackTrace();
  recorder.stop();
  recording = false;
} else {
  recording = true;
  recorder.start();
  recorder.stop();
  recording = false;
recorder.release();
finish();

代码示例来源:origin: stackoverflow.com

mediaRecorder = new MediaRecorder();
mediaRecorder.setAudioSource(MediaRecorder.AudioSource.CAMCORDER);
mediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
mediaRecorder.setOutputFile("/sdcard/myvideo1.mp4");
mediaRecorder.setMaxDuration(60000); // Set max duration 60 sec.
mediaRecorder.setMaxFileSize(50000000); // Set max file size 50Mb
mediaRecorder.setOrientationHint(VideoWithSurfaceVw.orientation);
try {
  mediaRecorder.prepare();
} catch (IllegalStateException e) {
  releaseMediaRecorder();
if (mediaRecorder != null) {
  mediaRecorder.release(); // release the recorder object
  mediaRecorder = new MediaRecorder();

代码示例来源:origin: stackoverflow.com

MediaRecorder recorder = new MediaRecorder();
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
recorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
recorder.setOutputFile(getFilesDir()+"/audio.m4a");
recorder.prepare();
recorder.start(); 
...
recorder.stop();
recorder.reset();
recorder.release()

代码示例来源:origin: stackoverflow.com

import android.media.MediaRecorder;
final MediaRecorder recorder = new MediaRecorder();

public void start() {
 recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
 recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
 recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
 recorder.setOutputFile(path);
 recorder.prepare();
 recorder.start();
}
 public void stop() {
 recorder.stop();
 recorder.release();
}

代码示例来源:origin: stackoverflow.com

MediaRecorder recorder = new MediaRecorder();
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
recorder.setOutputFile(PATH_NAME);
recorder.prepare();
recorder.start();   // Recording is now started
...
recorder.stop();
recorder.reset();   // You can reuse the object by going back to setAudioSource() step
recorder.release(); // Now the object cannot be reused

相关文章