您好,登录后才能下订单哦!
密码登录
登录注册
点击 登录注册 即表示同意《亿速云用户服务条款》
今天小编给大家分享一下java怎么初始化MediaRecorder的相关知识点,内容详细,逻辑清晰,相信大部分人都还太了解这方面的知识,所以分享这篇文章给大家参考一下,希望大家阅读完这篇文章后有所收获,下面我们一起来了解一下吧。
java中初始化MediaRecorder
实现代码:
private boolean initializeVideo() { Log.v(TAG, "initializeVideo"); if (mSurfaceHolder == null) { Log.v(TAG, "SurfaceHolder is null"); return false; } mMediaRecorderRecording = true; if (mMediaRecorder == null) mMediaRecorder = new MediaRecorder(); else mMediaRecorder.reset(); if (mCamera != null) { if (Integer.parseInt(Build.VERSION.SDK) >= 8) VideoCameraNew2.reconnect(mCamera); mCamera.release(); mCamera = null; } if (useFront && Integer.parseInt(Build.VERSION.SDK) >= 5) { if (isAvailableSprintFFC) { try { Method method = Class.forName("android.hardware.HtcFrontFacingCamera").getDeclaredMethod("getCamera", null); mCamera = (Camera) method.invoke(null, null); } catch (Exception ex) { Log.d(TAG, ex.toString()); } } else { mCamera = Camera.open(); Camera.Parameters parameters = mCamera.getParameters(); parameters.set("camera-id", 2); mCamera.setParameters(parameters); } VideoCameraNew.unlock(mCamera); mMediaRecorder.setCamera(mCamera); mVideoPreview.setOnClickListener(this); } mVideoPreview.setOnLongClickListener(this); mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA); mMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP); mMediaRecorder.setOutputFile(sender.getFileDescriptor()); mMediaRecorder.setVideoFrameRate(20); if (videoQualityHigh) { mMediaRecorder.setVideoSize(352,288); } else { mMediaRecorder.setVideoSize(176,144); } mMediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H263); mMediaRecorder.setPreviewDisplay(mSurfaceHolder.getSurface()); try { mMediaRecorder.prepare(); mMediaRecorder.setOnErrorListener(this); mMediaRecorder.start(); } catch (IOException exception) { releaseMediaRecorder(); finish(); return false; } return true; }
private boolean initializeVideo() { Log.v(TAG, "initializeVideo"); if (mSurfaceHolder == null) { Log.v(TAG, "SurfaceHolder is null"); return false; } mMediaRecorderRecording = true; if (mMediaRecorder == null) mMediaRecorder = new MediaRecorder(); else mMediaRecorder.reset(); if (mCamera != null) { if (Integer.parseInt(Build.VERSION.SDK) >= 8) VideoCameraNew2.reconnect(mCamera); mCamera.release(); mCamera = null; } if (useFront && Integer.parseInt(Build.VERSION.SDK) >= 5) { if (isAvailableSprintFFC) { try { Method method = Class.forName("android.hardware.HtcFrontFacingCamera").getDeclaredMethod("getCamera", null); mCamera = (Camera) method.invoke(null, null); } catch (Exception ex) { Log.d(TAG, ex.toString()); } } else { mCamera = Camera.open(); Camera.Parameters parameters = mCamera.getParameters(); parameters.set("camera-id", 2); mCamera.setParameters(parameters); } VideoCameraNew.unlock(mCamera); mMediaRecorder.setCamera(mCamera); mVideoPreview.setOnClickListener(this); } mVideoPreview.setOnLongClickListener(this); mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA); mMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP); mMediaRecorder.setOutputFile(sender.getFileDescriptor()); mMediaRecorder.setVideoFrameRate(20); if (videoQualityHigh) { mMediaRecorder.setVideoSize(352,288); } else { mMediaRecorder.setVideoSize(176,144); } mMediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H263); mMediaRecorder.setPreviewDisplay(mSurfaceHolder.getSurface()); try { mMediaRecorder.prepare(); mMediaRecorder.setOnErrorListener(this); mMediaRecorder.start(); } catch (IOException exception) { releaseMediaRecorder(); finish(); return false; } return true; }
private void releaseMediaRecorder() { Log.v(TAG, "Releasing media recorder."); if (mMediaRecorder != null) { mMediaRecorder.reset(); if (mCamera != null) { if (Integer.parseInt(Build.VERSION.SDK) >= 8) VideoCameraNew2.reconnect(mCamera); mCamera.release(); mCamera = null; } mMediaRecorder.release(); mMediaRecorder = null; } } public void onError(MediaRecorder mr, int what, int extra) { if (what == MediaRecorder.MEDIA_RECORDER_ERROR_UNKNOWN) { finish(); } }
private void releaseMediaRecorder() { Log.v(TAG, "Releasing media recorder."); if (mMediaRecorder != null) { mMediaRecorder.reset(); if (mCamera != null) { if (Integer.parseInt(Build.VERSION.SDK) >= 8) VideoCameraNew2.reconnect(mCamera); mCamera.release(); mCamera = null; } mMediaRecorder.release(); mMediaRecorder = null; } } public void onError(MediaRecorder mr, int what, int extra) { if (what == MediaRecorder.MEDIA_RECORDER_ERROR_UNKNOWN) { finish(); } }
private void stopVideoRecording() { Log.v(TAG, "stopVideoRecording"); if (mMediaRecorderRecording || mMediaRecorder != null) { Receiver.listener_video = null; t.interrupt(); RtpStreamSender.delay = 0; if (mMediaRecorderRecording && mMediaRecorder != null) { try { mMediaRecorder.setOnErrorListener(null); mMediaRecorder.setOnInfoListener(null); mMediaRecorder.stop(); } catch (RuntimeException e) { Log.e(TAG, "stop fail: " + e.getMessage()); } mMediaRecorderRecording = false; } releaseMediaRecorder(); } }
以上就是“java怎么初始化MediaRecorder”这篇文章的所有内容,感谢各位的阅读!相信大家阅读完这篇文章都有很大的收获,小编每天都会为大家更新不同的知识,如果还想学习更多的知识,请关注亿速云行业资讯频道。
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。