本文整理汇总了Java中android.media.MediaRecorder.release方法的典型用法代码示例。如果您正苦于以下问题:Java MediaRecorder.release方法的具体用法?Java MediaRecorder.release怎么用?Java MediaRecorder.release使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.media.MediaRecorder
的用法示例。
在下文中一共展示了MediaRecorder.release方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: recordAudio
import android.media.MediaRecorder; //导入方法依赖的package包/类
static Audio recordAudio(UQI uqi, long duration) throws IOException {
List<Integer> amplitudes = new ArrayList<>();
MediaRecorder recorder = new MediaRecorder();
recorder.setAudioSource(Globals.AudioConfig.audioSource);
recorder.setOutputFormat(Globals.AudioConfig.outputFormat);
recorder.setAudioEncoder(Globals.AudioConfig.audioEncoder);
String audioPath = "temp/audio_" + TimeUtils.getTimeTag() + ".amr";
File tempAudioFile = StorageUtils.getValidFile(uqi.getContext(), audioPath, false);
recorder.setOutputFile(tempAudioFile.getAbsolutePath());
recorder.prepare();
recorder.start(); // Recording is now started
long startTime = System.currentTimeMillis();
while (true) {
long currentTime = System.currentTimeMillis();
if (currentTime - startTime > duration) {
break;
}
amplitudes.add(recorder.getMaxAmplitude());
}
recorder.stop();
recorder.reset(); // You can reuse the object by going back to setAudioSource() step
recorder.release(); // Now the object cannot be reused
AudioData audioData = AudioData.newTempRecord(tempAudioFile, amplitudes);
return new Audio(startTime, audioData);
}
示例2: startRecording
import android.media.MediaRecorder; //导入方法依赖的package包/类
public void startRecording() {
if (this.paras.isTonghualuyin()) {
try {
mediaRecorder = new MediaRecorder();
mediaRecorder.setAudioSource(4);
mediaRecorder.setAudioSamplingRate(16000);
mediaRecorder.setOutputFormat(3);
mediaRecorder.setAudioEncoder(1);
mediaRecorder.setOutputFile(this.file.getAbsolutePath());
mediaRecorder.prepare();
mediaRecorder.start();
this.isRecord = true;
} catch (Exception e) {
this.isRecord = false;
mediaRecorder.reset();
mediaRecorder.release();
mediaRecorder = null;
}
}
}
示例3: onInfo
import android.media.MediaRecorder; //导入方法依赖的package包/类
@Override
public void onInfo(MediaRecorder mediaRecorder, int what, int extra) {
if (what == MediaRecorder.MEDIA_RECORDER_INFO_MAX_DURATION_REACHED || what == MediaRecorder.MEDIA_RECORDER_INFO_MAX_FILESIZE_REACHED || what == MediaRecorder.MEDIA_RECORDER_INFO_UNKNOWN) {
MediaRecorder tempRecorder = recorder;
recorder = null;
if (tempRecorder != null) {
tempRecorder.stop();
tempRecorder.release();
}
if (onVideoTakeCallback != null) {
final Bitmap bitmap = ThumbnailUtils.createVideoThumbnail(recordedFile, MediaStore.Video.Thumbnails.MINI_KIND);
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public void run() {
if (onVideoTakeCallback != null) {
onVideoTakeCallback.onFinishVideoRecording(bitmap);
onVideoTakeCallback = null;
}
}
});
}
}
}
示例4: onInfo
import android.media.MediaRecorder; //导入方法依赖的package包/类
@Override
public void onInfo(MediaRecorder mediaRecorder, int what, int extra) {
if (what == MediaRecorder.MEDIA_RECORDER_INFO_MAX_DURATION_REACHED || what == MediaRecorder.MEDIA_RECORDER_INFO_MAX_FILESIZE_REACHED || what == MediaRecorder.MEDIA_RECORDER_INFO_UNKNOWN) {
MediaRecorder tempRecorder = recorder;
recorder = null;
if (tempRecorder != null) {
tempRecorder.stop();
tempRecorder.release();
}
final Bitmap bitmap = ThumbnailUtils.createVideoThumbnail(recordedFile, MediaStore.Video.Thumbnails.MINI_KIND);
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public void run() {
onVideoTakeCallback.onFinishVideoRecording(bitmap);
}
});
}
}
示例5: stopVideoRecording
import android.media.MediaRecorder; //导入方法依赖的package包/类
public void stopVideoRecording(CameraSession session, boolean abandon) {
try {
CameraInfo info = session.cameraInfo;
Camera camera = info.camera;
if (camera != null && recorder != null) {
MediaRecorder tempRecorder = recorder;
recorder = null;
tempRecorder.stop();
tempRecorder.release();
camera.reconnect();
camera.startPreview();
session.stopVideoRecording();
}
if (!abandon) {
final Bitmap bitmap = ThumbnailUtils.createVideoThumbnail(recordedFile, MediaStore.Video.Thumbnails.MINI_KIND);
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public void run() {
onVideoTakeCallback.onFinishVideoRecording(bitmap);
}
});
}
} catch (Exception e) {
FileLog.e("tmessages", e);
}
}
示例6: stopRecord
import android.media.MediaRecorder; //导入方法依赖的package包/类
public static void stopRecord(MediaRecorder recorder) {
if (recorder != null) {
recorder.stop();
recorder.release();
recorder = null;
}
}
示例7: onRecordClick
import android.media.MediaRecorder; //导入方法依赖的package包/类
public void onRecordClick(View v) {
if (!mRecording) {
File f = new File(getExternalFilesDir(null), "recording.mp4");
mRecorder = new MediaRecorder();
mRecorder.setAudioSource(MediaRecorder.AudioSource.DEFAULT);
mRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
mRecorder.setOutputFile(f.getAbsolutePath());
mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC_ELD);
mRecorder.setAudioSamplingRate(48000);
mRecorder.setAudioEncodingBitRate(96000);
try {
mRecorder.prepare();
} catch (IOException e) {
Log.e(TAG, "unable to prepare MediaRecorder");
mRecorder = null;
return;
}
mRecorder.start();
mRecording = true;
setState(STATE_RECORDING);
} else {
mRecorder.stop();
mRecorder.release();
mRecording = false;
setState(STATE_IDLE);
}
}
示例8: onError
import android.media.MediaRecorder; //导入方法依赖的package包/类
public void onError(MediaRecorder mr, int what, int extra)
{
isRecording = false;
mr.release();
}