zoukankan      html  css  js  c++  java
  • Android视频录制

    一、通过Intent调用系统录像程序

    final int CODE_VIDEO_SYS = 0x001 ;
    
    Intent intent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
    startActivityForResult(intent, CODE_VIDEO_SYS);
    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
      super.onActivityResult(requestCode, resultCode, data);
      if(resultCode== Activity.RESULT_OK){
        switch (requestCode){
          case CODE_VIDEO_SYS :
            Uri uri = data.getData() ;
            if(uri!=null){
              Toast.makeText(getActivity(),"视频位置:"+uri.getPath(),Toast.LENGTH_SHORT).show();
            }
            break ;
        }
        }
    }

    二、调用CameraMediaRecorder录制视频

    To quickly switch to video recording mode, use these steps:

    1. Obtain and initialize a Camera and start preview as described above.
    2. Call unlock() to allow the media process to access the camera.
    3. Pass the camera to setCamera(Camera). See MediaRecorder information about video recording.
    4. When finished recording, call reconnect() to re-acquire and re-lock the camera.
    5. If desired, restart preview and take more photos or videos.
    6. Call stopPreview() and release() as described above.

    This class is not thread-safe, and is meant for use from one event thread. Most long-running operations (preview, focus, photo capture, etc) happen asynchronously and invoke callbacks as necessary. Callbacks will be invoked on the event thread open(int) was called from. This class's methods must never be called from multiple threads at once.

    Caution: Different Android-powered devices may have different hardware specifications, such as megapixel ratings and auto-focus capabilities. In order for your application to be compatible with more devices, you should not make assumptions about the device camera specifications.

    基本步骤和使用Camera拍照一样,直到第6步启用预览之后,点击按钮开始录制视频时

    void startRecord(){
      mRecorder = new MediaRecorder();
      //在某些手机上共享Camera会起冲突,导致录制的视频花屏,所以需要停止Camera的预览,启用MediaRecoder的预览   mCamera.stopPreview();   mCamera.unlock();   mRecorder.setCamera(mCamera);   mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);   mRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
      CamcorderProfile profile = CamcorderProfile.get(CamcorderProfile.QUALITY_480P);   mRecorder.setProfile(profile);   mRecorder.setPreviewDisplay(mSurface.getHolder().getSurface());   mRecorder.setOutputFile("/sdcard/video.mp4");   try {     mRecorder.prepare();     mRecorder.start();   } catch (IOException e) {     e.printStackTrace();   } }

    停止录制视频

    void stopRecord(){
      mRecorder.stop();
      mRecorder.reset();
      try {
        mCamera.reconnect();
      } catch (IOException e) {
        e.printStackTrace();
      }
    }
  • 相关阅读:
    掌游 新项目:我采用NH连接MySql所遇到的问题
    运行时动态将字符串编译为C#可执行代码
    数据库连接字符串用IP死活连不上,只能用计算机名连,ADO或ORM错误提示为表“对象”无效
    File.Copy是Copy完再执行下一句的,自己验证过了。
    window.external.XXX 判断是否有这个方法
    java构建工具——ant使用
    大数据学习之路(1)Hadoop生态体系结构
    Java经典代码片段——使用NIO进行快速的文件拷贝
    Java代码片段——向文件末尾添加内容
    JAVA几种常见的编码格式(转)
  • 原文地址:https://www.cnblogs.com/alexthecoder/p/4365251.html
Copyright © 2011-2022 走看看