Android录制视频---LandscapeVideoCamera的使用详情及修改
来源:互联网 发布:苹果软件更新 编辑:程序博客网 时间:2024/05/16 08:35
LandscapeVideoCamera是一个非常强大的android 视频录制库,可以选择视频尺寸以及视频质量,只允许横屏录制。对于LandscapeVideoCamera的好处就不多介绍了。网上已经有很多人介绍了
个人最忍受不了一个点是:强制用户横屏,竖屏的时候是不让录制的,这一点真的有点坑,录制过程中不小心斜过来了呢?它就停了!它就停了!它就停了!(个人体验,不否认LandscapeVideoCamera本身的强大~~~)
......
因项目需求原因对其进行了如下修改:
1:取消了竖屏时停止录制的动作。
2:录制结束后增加了重录功能。
3:增加了倒计时开始录制功能。
4:增加了录制过程中开启灯光的功能。
5:需求原因改变了其UI。
效果图↓
使用详情↓
调用类:
import android.content.Intent;import android.os.Bundle;import android.support.v7.app.AppCompatActivity;import android.util.Log;import android.view.View;import android.widget.Button;import android.widget.Toast;import com.jmolsmobile.landscapevideocapture.VideoCaptureActivity;import com.jmolsmobile.landscapevideocapture.configuration.CaptureConfiguration;import java.io.File;import java.io.FileInputStream;import java.text.DecimalFormat;import static com.jmolsmobile.landscapevideocapture.configuration.PredefinedCaptureConfigurations.CaptureQuality.HIGH;import static com.jmolsmobile.landscapevideocapture.configuration.PredefinedCaptureConfigurations.CaptureResolution.RES_1440P;/** * @date 2017/5/8 * @authro lipeng */public class MainActivity extends AppCompatActivity { private Button test; private CaptureConfiguration configuration; public static final String EXTRA_OUTPUT_FILENAME = "com.jmolsmobile.extraoutputfilename"; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); test = (Button) findViewById(R.id.test); initLandScapeVideoCapture(); test.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { intentLandScapeVideoCapture(); } }); } //初始化CaptureConfiguration private void initLandScapeVideoCapture(){ configuration = new CaptureConfiguration(RES_1440P, HIGH,60,1024,true,true); } private void intentLandScapeVideoCapture(){ final Intent intent = new Intent(MainActivity.this, VideoCaptureActivity.class); intent.putExtra(VideoCaptureActivity.EXTRA_CAPTURE_CONFIGURATION,configuration); intent.putExtra(VideoCaptureActivity.EXTRA_OUTPUT_FILENAME, "文件名"); startActivityForResult(intent, result); } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if(resultCode==RESULT_OK){ Log.e("hlog","视频路径:"+data.getStringExtra(EXTRA_OUTPUT_FILENAME)); Log.e("hlog","视频大小:"+getVideoSize(data.getStringExtra(EXTRA_OUTPUT_FILENAME)+"M")); double size=getVideoSize(data.getStringExtra(EXTRA_OUTPUT_FILENAME)); Toast.makeText(MainActivity.this, "视频大小:"+size+"M", Toast.LENGTH_SHORT).show(); }else if(resultCode==9999){ final Intent intent = new Intent(MainActivity.this, VideoCaptureActivity.class); intent.putExtra(VideoCaptureActivity.EXTRA_CAPTURE_CONFIGURATION,configuration); intent.putExtra(VideoCaptureActivity.EXTRA_OUTPUT_FILENAME, "DFA2R34FAS12"); startActivityForResult(intent, 100); } } private double getVideoSize(String videoPath){ File file = new File(videoPath); long fileLength = 0; try { fileLength = getFileSize(file); } catch (Exception e) { e.printStackTrace(); } DecimalFormat df = new DecimalFormat("#.00"); double fileSize = Double.valueOf(df.format((double)fileLength/1048576)); return fileSize; } /** * 获取指定文件大小 * * @return * @throws Exception */ private static long getFileSize(File file) throws Exception { long size = 0; if (file.exists()) { FileInputStream fis = null; fis = new FileInputStream(file); size = fis.available(); } else { file.createNewFile(); Log.e("获取文件大小", "文件不存在!"); } return size; }}
CaptureConfiguration对象有多种构造方式如下:
private CaptureConfiguration() { // Default configuration } @Deprecated public CaptureConfiguration(CaptureResolution resolution, CaptureQuality quality) { videoWidth = resolution.width; videoHeight = resolution.height; bitrate = resolution.getBitrate(quality); } @Deprecated public CaptureConfiguration(CaptureResolution resolution, CaptureQuality quality, int maxDurationSecs, int maxFilesizeMb, boolean showTimer) { this(resolution, quality, maxDurationSecs, maxFilesizeMb, showTimer, false); this.showTimer = showTimer; } @Deprecated public CaptureConfiguration(CaptureResolution resolution, CaptureQuality quality, int maxDurationSecs, int maxFilesizeMb, boolean showTimer, boolean allowFrontFacingCamera) { this(resolution, quality, maxDurationSecs, maxFilesizeMb); this.showTimer = showTimer; this.allowFrontFacingCamera = allowFrontFacingCamera; } @Deprecated public CaptureConfiguration(CaptureResolution resolution, CaptureQuality quality, int maxDurationSecs, int maxFilesizeMb, boolean showTimer, boolean allowFrontFacingCamera, int videoFPS) { this(resolution, quality, maxDurationSecs, maxFilesizeMb, showTimer, allowFrontFacingCamera); videoFramerate = videoFPS; } @Deprecated public CaptureConfiguration(CaptureResolution resolution, CaptureQuality quality, int maxDurationSecs, int maxFilesizeMb) { this(resolution, quality); maxDurationMs = maxDurationSecs * MSEC_TO_SEC; maxFilesizeBytes = maxFilesizeMb * MBYTE_TO_BYTE; } @Deprecated public CaptureConfiguration(int videoWidth, int videoHeight, int bitrate) { this.videoWidth = videoWidth; this.videoHeight = videoHeight; this.bitrate = bitrate; } @Deprecated public CaptureConfiguration(int videoWidth, int videoHeight, int bitrate, int maxDurationSecs, int maxFilesizeMb) { this(videoWidth, videoHeight, bitrate); maxDurationMs = maxDurationSecs * MSEC_TO_SEC; maxFilesizeBytes = maxFilesizeMb * MBYTE_TO_BYTE; }
本文中使用的是:
@Deprecated public CaptureConfiguration(CaptureResolution resolution, CaptureQuality quality, int maxDurationSecs, int maxFilesizeMb, boolean showTimer, boolean allowFrontFacingCamera) { this(resolution, quality, maxDurationSecs, maxFilesizeMb); this.showTimer = showTimer; this.allowFrontFacingCamera = allowFrontFacingCamera; }
resolution对应值有:
RES_360P(WIDTH_360P, HEIGHT_360P, BITRATE_HQ_360P, BITRATE_MQ_360P, BITRATE_LQ_360P), // LDRES_480P(WIDTH_480P, HEIGHT_480P, BITRATE_HQ_480P, BITRATE_MQ_480P, BITRATE_LQ_480P), // SDRES_720P(WIDTH_720P, HEIGHT_720P, BITRATE_HQ_720P, BITRATE_MQ_720P, BITRATE_LQ_720P), // HD readyRES_1080P(WIDTH_1080P, HEIGHT_1080P, BITRATE_HQ_1080P, BITRATE_MQ_1080P, BITRATE_LQ_1080P), // HDRES_1440P(WIDTH_1440P, HEIGHT_1440P, BITRATE_HQ_1440P, BITRATE_MQ_1440P, BITRATE_LQ_1440P), // 2KRES_2160P(WIDTH_2160P, HEIGHT_2160P, BITRATE_HQ_2160P, BITRATE_MQ_2160P, BITRATE_LQ_2160P); // 4K
quality对应值有:
public enum CaptureQuality { LOW, MEDIUM, HIGH; }
maxDurationSecs为录制的最长时间,单位为秒。maxFilesizeMb为录制的最大大小,单位为M。showTimer为是否显示录制计时器。allowFrontFacingCamera为是否允许前置摄像头切换。
LandscapeVideoCamera源码地址:https://github.com/JeroenMols/LandscapeVideoCamera
本文demo下载:点击打开链接
希望对大家有帮助~!
2 0
- Android录制视频---LandscapeVideoCamera的使用详情及修改
- 视频录制框架LandscapeVideoCamera
- LandscapeVideoCamera——强大的自定义Android视频类库
- 录制音视频及promise的使用
- android 录制视频及调取本地视频
- Android 使用意图录制视频
- vlc android的编译及截图,录制视频等功能
- vlc android的编译及截图,录制视频等功能
- vlc android的编译及截图,录制视频等功能
- vlc android的编译及截图,录制视频等功能
- Android MediaRecorder 录制视频出现的问题及解决
- Android视频录制及提取图片操作
- android多媒体-视频录制及存储
- Android开发之使用MediaRecorder录制视频
- Android开发之使用MediaRecorder录制视频
- Android使用MediaRecorder类进行录制视频
- android camera使用ISO值录制视频
- android使用mediarecorder和camera录制视频
- 银行借我钱花
- Mac版WebStorm安装
- BootStrap基础
- js实现键盘控制移动div
- rel="stylesheet" 是什么意思?
- Android录制视频---LandscapeVideoCamera的使用详情及修改
- SYSFS以及设备文件或kobject目录创建的关系
- 相关向量机
- Python Numpy Tutorial: 字典
- oracle编译存储过程卡死,随笔录5.8
- POJ 3617 Best Cow Line
- Java中8种基本数据类型及其默认值
- Coursera机器学习(Andrew Ng)笔记:无监督学习与维度约减
- 一些常用的流