大佬教程收集整理的这篇文章主要介绍了Bug录制视频android,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我的视频处理器:
@Override public void onCreate() { super.onCreate(); isRunning = true; iDalerta = Common.getStorage().getString(Constants.ID_ALERTA_serviCE,""); videoCount = 1; mIntentRecorder = new Intent(VideoHandlerservice.this,Recorderservice.class); mIntentSend = new Intent(VideoHandlerservice.this,SendVideoservice.class); updateVideoTime(); mIntentRecorder.putExtra(Constants.VIDEO_TIME,videoTimE); mIntentRecorder.putExtra(Constants.ID_ALERTA_serviCE,iDalerta); mIntentRecorder.putExtra(Constants.COUNT_ALERTA,videoCount); startservice(mIntentRecorder); newVideo(); } public void newVideo() { Common.log("new Video"); new Handler().postDelayed(new Runnable() { @Override public void run() { videoCount++; startNewVideo(); if (videoCount == 2) sendVideo(4000); } },videoTime + 2000); } public void startNewVideo() { final Intent intentRecorder = new Intent(VideoHandlerservice.this,Recorderservice.class); intentRecorder.putExtra(Constants.VIDEO_TIME,videoTimE); Common.log("iDalerta " + iDalerta); intentRecorder.putExtra(Constants.ID_ALERTA_serviCE,iDalerta); intentRecorder.putExtra(Constants.COUNT_ALERTA,videoCount); stopservice(intentRecorder); if (Common.getStorage().getBoolean(Constants.RECORDER_ACTIVE,falsE)) { if (Common.getStorage().getString(Constants.ID_ALERTA_serviCE,"") != null && Common.getStorage().getString(Constants.ID_ALERTA_serviCE,"").length() > 0) { new Handler().postDelayed(new Runnable() { @Override public void run() { Common.log("Start service recorder"); startservice(intentRecorder); newVideo(); } },5000); } } else new Handler().postDelayed(new Runnable() { @Override public void run() { startNewVideo(); } },5000); }
这是记录的过程:
@Override public int onStartCommand(Intent intent,int flags,int startId) { Common.log("onStartCommand"); if (intent != null && ((Common.getStorage().getString(Constants.ID_ALERTA_serviCE,"").length() > 0))) { windowManager = (WindowManager) this.getSystemservice(Context.WINDOW_serviCE); mLayoutParams = new WindowManager.LayoutParams( 1,1,WindowManager.LayoutParams.TYPE_SYstem_OVERLAY,WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH,PixelFormat.TRANSLUCENT ); mLayoutParams.gravity = Gravity.LEFT | Gravity.TOP; //Cojo Información del videohandler Common.log("Intent disTinto de null"); mVideoTime = intent.getIntextra(Constants.VIDEO_TIME,15000); mIDalerta = intent.getStringExtra(Constants.ID_ALERTA_serviCE); mVideoCount = intent.getIntextra(Constants.COUNT_ALERTA,1); Common.log("Video time" + mVideoTimE); Common.getStorage().putBoolean(Constants.RECORDER_ACTIVE,truE); initRecording(); } return START_NOT_STICKY; } public void initRecording() { Common.log("INIT RECORDING IN"); surfaceView = new SurfaceView(this); windowManager.addView(surfaceView,mLayoutParams); surfaceView.getHolder().addCallBACk(this); Common.log("INIT RECORDING OUT"); } @Nullable @Override public IBinder onBind(Intent intent) { return null; } @Override public void onDestroy() { Common.log("onDestroy Video"); PreferenceHelper preferenceHelper = PreferenceHelper.newInstance(Recorderservice.this,Constants.user_PREFERENCES); preferenceHelper.setBoolean(Constants.IS_RECORDING,falsE); try { camera.setPreviewCallBACk(null); } catch (Exception E){ Common.log("error setPrevieCallBACk" + (e.getmessage() != null ? e.getmessage() : "sin mensaje")); } try { muteSounds(false); } catch (Exception E) { Common.log(e.getmessage()); } try { Common.log("media recorder stop"); mediaRecorder.stop(); Common.log("media recorder reset"); mediaRecorder.reset(); Common.log("media recorder release"); mediaRecorder.release(); Common.log("media camera lock"); camera.lock(); Common.log("media camera release"); camera.release(); } catch (Exception E) { } Common.log("onDestroy Video"); Common.getStorage().putBoolean(Constants.RECORDER_ACTIVE,falsE); Recorderservice.super.onDestroy(); System.exit(0); } @Override public void surfaceCreated(SurfaceHolder holder) { mSurfaceHolder = holder; Common.log("SurfaceCreated"); try { try { muteSounds(true); } catch (Exception E) { Common.log(e.getmessage()); } Common.log("CAMERA OPEN 1"); try { camera = Camera.open(1); } catch (RuntimeException E) { Common.log(e.getmessage()); } Common.log("CAMERA OPEN 2"); /////////////////////////// mCamCoderProfile = CamcorderProfile.get(1,CamcorderProfile.QUALITY_LOW); mCamCoderProfile.videoCodec = MediaRecorder.VideoEncoder.MPEG_4_SP; mCamCoderProfile.audioCodec = MediaRecorder.AudioEncoder.AAc; /////////////////////////// startRecorder(); } catch (Exception E) { if (e.getmessage() != null) Common.log(e.getmessage()); } } public void muteSounds(Boolean mutE) { Common.log("MUTE SOUNDS IN"); Au@L_655_11@manager mgr = ((Au@L_655_11@manager) getSystemservice(Context.AUdio_serviCE)); mgr.setStreAMMute(Au@L_655_11@manager.STREAM_SYstem,truE); if (Build.VERSION.SDK_INT >= Build.VERSION_CODEs.M) { if (mutE) { mgr.adjustStreamVolume(Au@L_655_11@manager.STREAM_SYstem,Au@L_655_11@manager.ADJUST_MUTE,0); mgr.adjustVolume(Au@L_655_11@manager.ADJUST_MUTE,0); mgr.adjustVolume(Au@L_655_11@manager.FLAG_REMOVE_SOUND_AND_VIBRATE,0); } else { mgr.adjustStreamVolume(Au@L_655_11@manager.STREAM_SYstem,Au@L_655_11@manager.ADJUST_UNMUTE,0); mgr.adjustVolume(Au@L_655_11@manager.ADJUST_UNMUTE,0); } } else { mgr.setStreAMMute(Au@L_655_11@manager.STREAM_SYstem,mutE); mgr.setStreAMMute(Au@L_655_11@manager.STREAM_MUSIC,mutE); if (mutE) { mOlderVolumen = mgr.getStreamVolume(Au@L_655_11@manager.STREAM_RING); mgr.setStreamVolume(Au@L_655_11@manager.STREAM_RING,0); } else mgr.setStreamVolume(Au@L_655_11@manager.STREAM_RING,mOlderVolumen,0); mgr.adjustVolume(Au@L_655_11@manager.ADJUST_LOWER,0); } Common.log("MUTE SOUNDS OUT"); } public void startRecorder() { mediaRecorder = new MediaRecorder(); camera.unlock(); mediaRecorder.setCamera(camera); mediaRecorder.setPreviewDisplay(mSurfaceHolder.getSurface()); mediaRecorder.setAudiosource(MediaRecorder.Audiosource.CAMCORDER); mediaRecorder.setVideosource(MediaRecorder.Videosource.CAMERA); mediaRecorder.setProfile(mCamCoderProfilE); videoFile = new File(Environment.getExternalStorageDirectory() + "/" + "wbunker_" + mIDalerta + "_" + mVideoCount + ".mp4"); Common.log("Video rercorder name file " + videoRecording); mediaRecorder.setOutputFile(videoFile.getPath()); mediaRecorder.setOrientationHint(270); try { Common.log("mediaRecorder prepare"); mediaRecorder.prepare(); Common.log("mediaRecorder prepare"); } catch (Exception E) { } Common.log("mediaRecorder start"); mediaRecorder.start(); Common.log("mediaRecorder start"); Common.log("Estoy grabando macho"); }
当我尝试停止服务时,服务停止,但即使杀死应用程序也不会释放相机.有人能帮我吗??提前致谢.
以上是大佬教程为你收集整理的Bug录制视频android全部内容,希望文章能够帮你解决Bug录制视频android所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。