本文整理了Java中android.media.MediaRecorder.setOutputFormat()
方法的一些代码示例,展示了MediaRecorder.setOutputFormat()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。MediaRecorder.setOutputFormat()
方法的具体详情如下:
包路径:android.media.MediaRecorder
类名称:MediaRecorder
方法名:setOutputFormat
暂无
代码示例来源:origin: ankidroid/Anki-Android
private MediaRecorder initMediaRecorder() {
MediaRecorder mr = new MediaRecorder();
mr.setAudioSource(MediaRecorder.AudioSource.MIC);
mr.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
mStatus = Status.INITIALIZED;
mr.setOutputFile(mAudioPath); // audioPath
// could
// change
return mr;
}
};
代码示例来源:origin: commonsguy/cw-omnibus
void start() {
recorder=new MediaRecorder();
recorder.setVideoSource(MediaRecorder.VideoSource.SURFACE);
recorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
recorder.setVideoFrameRate(config.frameRate);
recorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264);
recorder.setVideoSize(config.width, config.height);
recorder.setVideoEncodingBitRate(config.bitRate);
recorder.setOutputFile(output.getAbsolutePath());
try {
recorder.prepare();
vdisplay=projection.createVirtualDisplay("andcorder",
config.width, config.height, config.density,
VIRT_DISPLAY_FLAGS, recorder.getSurface(), null, null);
beeper.startTone(ToneGenerator.TONE_PROP_ACK);
recorder.start();
}
catch (IOException e) {
throw new RuntimeException("Exception preparing recorder", e);
}
}
代码示例来源:origin: stackoverflow.com
MediaRecorder recorder = new MediaRecorder();
recorder.setCamera(camera);
recorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
recorder.prepare();
代码示例来源: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();
代码示例来源:origin: guardianproject/haven
private boolean prepare(Camera camera) {
mCamera = camera;
mMediaRecorder = new MediaRecorder();
mCamera.unlock();
mMediaRecorder.setCamera(mCamera);
mMediaRecorder.setPreviewDisplay(mHolder.getSurface());
// mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.DEFAULT);
mMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
// mMediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
mMediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.MPEG_4_SP);
mMediaRecorder.setMaxDuration(mSeconds);
mMediaRecorder.setOutputFile(mOutputFile);
try {
mMediaRecorder.prepare();
} catch(IllegalStateException e) {
Log.d("ERROR", "IllegalStateException preparing MediaRecorder: " + e.getMessage());
releaseMediaRecorder();
return false;
} catch (IOException e) {
Log.d("ERROR", "IOException preparing MediaRecorder: " + e.getMessage());
releaseMediaRecorder();
return false;
}
return true;
}
代码示例来源:origin: commonsguy/cw-omnibus
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
recorder.setOutputFormat(MediaRecorder.OutputFormat.RAW_AMR);
recorder.setOutputFile(getStreamFd());
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
recorder.setAudioChannels(2);
recorder.prepare();
recorder.start();
代码示例来源:origin: willowtreeapps/Hyperion-Android
static void prepare(@NonNull Context context) throws RecordingException {
mediaRecorder = new MediaRecorder();
projectionManager = (MediaProjectionManager) context
.getSystemService(Context.MEDIA_PROJECTION_SERVICE);
WindowManager windowManager = (WindowManager)
context.getSystemService(Context.WINDOW_SERVICE);
displayMetrics = new DisplayMetrics();
windowManager.getDefaultDisplay().getMetrics(displayMetrics);
createDirectoryIfNeeded(context);
String videoId = UUID.randomUUID().toString();
outputPath = context.getFilesDir().getPath() + "/hyperion_recorder/" + videoId + ".mp4";
try {
//mediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
mediaRecorder.setVideoSource(MediaRecorder.VideoSource.SURFACE);
mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
mediaRecorder.setOutputFile(outputPath);
mediaRecorder.setVideoSize(displayMetrics.widthPixels, displayMetrics.heightPixels);
mediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264);
//mediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
mediaRecorder.setVideoEncodingBitRate(512 * 2000);
mediaRecorder.setVideoFrameRate(30);
int rotation = windowManager.getDefaultDisplay().getRotation();
int orientation = ORIENTATIONS.get(rotation + 90);
mediaRecorder.setOrientationHint(orientation);
mediaRecorder.prepare();
} catch (IOException e) {
throw new RecordingException("Failed to initialize the media recorder.", e);
}
}
代码示例来源:origin: commonsguy/cw-omnibus
BASENAME);
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
recorder.setOutputFile(output.getAbsolutePath());
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
recorder.setAudioEncodingBitRate(160 * 1024);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
recorder.prepare();
recorder.start();
代码示例来源:origin: stackoverflow.com
Socket socket = new Socket(serverAddr, serverPort);
socket.setTcpNoDelay(true);
ParcelFileDescriptor pfd = ParcelFileDescriptor.fromSocket(socket);
Camera camera = Camera.open();
camera.unlock();
MediaRecorder recorder = new MediaRecorder();
recorder.setCamera(camera);
recorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
recorder.setVideoEncoder(MediaRecorder.VideoEncoder.H263);
recorder.setOutputFile(pfd.getFileDescriptor());
recorder.setPreviewDisplay(surfaceView.getHolder().getSurface());
recorder.setVideoFrameRate(15);
recorder.setVideoSize(480, 320);
recorder.prepare();
recorder.start();
代码示例来源:origin: stackoverflow.com
recorder = new MediaRecorder();
recorder.setAudioSource(MediaRecorder.AudioSource.VOICE_COMMUNICATION);
recorder.setOutputFormat(MediaRecorder.OutputFormat.AMR_NB);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
recorder.setOutputFile(audiofile.getAbsolutePath());
try {
recorder.prepare();
} catch (IllegalStateException e) {
e.printStackTrace();
e.printStackTrace();
recorder.start();
recordstarted = true;
代码示例来源:origin: google-ar/sceneform-android-sdk
private void setUpMediaRecorder() throws IOException {
mediaRecorder.setVideoSource(MediaRecorder.VideoSource.SURFACE);
mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
mediaRecorder.setOutputFile(videoPath.getAbsolutePath());
mediaRecorder.setVideoEncodingBitRate(bitRate);
mediaRecorder.setVideoFrameRate(frameRate);
mediaRecorder.setVideoSize(videoSize.getWidth(), videoSize.getHeight());
mediaRecorder.setVideoEncoder(videoCodec);
mediaRecorder.prepare();
try {
mediaRecorder.start();
} catch (IllegalStateException e) {
Log.e(TAG, "Exception starting capture: " + e.getMessage(), e);
}
}
代码示例来源: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());
代码示例来源: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) {
代码示例来源:origin: florent37/CameraFragment
@Override
protected boolean prepareVideoRecorder() {
videoRecorder = new MediaRecorder();
try {
videoRecorder.setAudioSource(MediaRecorder.AudioSource.CAMCORDER);
videoRecorder.setVideoSource(MediaRecorder.VideoSource.SURFACE);
videoRecorder.setOutputFormat(camcorderProfile.fileFormat);
videoRecorder.setVideoFrameRate(camcorderProfile.videoFrameRate);
videoRecorder.setVideoSize(videoSize.getWidth(), videoSize.getHeight());
videoRecorder.setAudioChannels(camcorderProfile.audioChannels);
videoRecorder.setAudioSamplingRate(camcorderProfile.audioSampleRate);
videoRecorder.setAudioEncoder(camcorderProfile.audioCodec);
videoRecorder.setOutputFile(outputFilePath);
videoRecorder.prepare();
代码示例来源: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 = new MediaRecorder();
mediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
mediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
mediaRecorder.start();
代码示例来源:origin: florent37/CameraFragment
@Override
protected boolean prepareVideoRecorder() {
videoRecorder = new MediaRecorder();
try {
camera.lock();
videoRecorder.setCamera(camera);
videoRecorder.setAudioSource(MediaRecorder.AudioSource.DEFAULT);
videoRecorder.setVideoSource(MediaRecorder.VideoSource.DEFAULT);
videoRecorder.setOutputFormat(camcorderProfile.fileFormat);
videoRecorder.setVideoFrameRate(camcorderProfile.videoFrameRate);
videoRecorder.setVideoSize(videoSize.getWidth(), videoSize.getHeight());
videoRecorder.setAudioChannels(camcorderProfile.audioChannels);
videoRecorder.setAudioSamplingRate(camcorderProfile.audioSampleRate);
videoRecorder.setAudioEncoder(camcorderProfile.audioCodec);
videoRecorder.setOutputFile(outputPath.toString());
videoRecorder.setPreviewDisplay(surface);
videoRecorder.prepare();
代码示例来源:origin: chat-sdk/chat-sdk-android
public File record(String name) {
stopRecording();
String path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOCUMENTS).getAbsolutePath() + AudioMessageDirectory + File.separator;
File file = new File(path);
file.mkdir();
path += name;
Timber.v("Recording to: " + path);
recorder = new MediaRecorder();
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
recorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
recorder.setOutputFile(path);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
try {
recorder.prepare();
} catch (IOException e) {
ChatSDK.logError(e);
}
recorder.start();
startTime = System.currentTimeMillis();
return new File (path);
}
代码示例来源:origin: stackoverflow.com
MediaRecorder recorder = new MediaRecorder();
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
if (Build.VERSION.SDK_INT >= 10) {
recorder.setAudioSamplingRate(44100);
recorder.setAudioEncodingBitRate(96000);
recorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
} else {
// older version of Android, use crappy sounding voice codec
recorder.setAudioSamplingRate(8000);
recorder.setAudioEncodingBitRate(12200);
recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
}
recorder.setOutputFile(file.getAbsolutePath());
try {
recorder.prepare();
} catch (IOException e) {
throw new RuntimeException(e);
}
代码示例来源:origin: dkim0419/SoundRecorder
public void startRecording() {
setFileNameAndPath();
mRecorder = new MediaRecorder();
mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
mRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
mRecorder.setOutputFile(mFilePath);
mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
mRecorder.setAudioChannels(1);
if (MySharedPreferences.getPrefHighQuality(this)) {
mRecorder.setAudioSamplingRate(44100);
mRecorder.setAudioEncodingBitRate(192000);
}
try {
mRecorder.prepare();
mRecorder.start();
mStartingTimeMillis = System.currentTimeMillis();
//startTimer();
//startForeground(1, createNotification());
} catch (IOException e) {
Log.e(LOG_TAG, "prepare() failed");
}
}
代码示例来源: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;
}
内容来源于网络,如有侵权,请联系作者删除!