本文主要是介绍Android录制视频---LandscapeVideoCamera的使用详情及修改,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
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";@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);test = (Button) findViewById(R.id.test);initLandScapeVideoCapture();test.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View view) {intentLandScapeVideoCapture();}});}//初始化CaptureConfigurationprivate 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);}@Overrideprotected 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}@Deprecatedpublic CaptureConfiguration(CaptureResolution resolution, CaptureQuality quality) {videoWidth = resolution.width;videoHeight = resolution.height;bitrate = resolution.getBitrate(quality);}@Deprecatedpublic CaptureConfiguration(CaptureResolution resolution, CaptureQuality quality, int maxDurationSecs,int maxFilesizeMb, boolean showTimer) {this(resolution, quality, maxDurationSecs, maxFilesizeMb, showTimer, false);this.showTimer = showTimer;}@Deprecatedpublic CaptureConfiguration(CaptureResolution resolution, CaptureQuality quality, int maxDurationSecs,int maxFilesizeMb, boolean showTimer, boolean allowFrontFacingCamera) {this(resolution, quality, maxDurationSecs, maxFilesizeMb);this.showTimer = showTimer;this.allowFrontFacingCamera = allowFrontFacingCamera;}@Deprecatedpublic CaptureConfiguration(CaptureResolution resolution, CaptureQuality quality, int maxDurationSecs,int maxFilesizeMb, boolean showTimer, boolean allowFrontFacingCamera,int videoFPS) {this(resolution, quality, maxDurationSecs, maxFilesizeMb, showTimer, allowFrontFacingCamera);videoFramerate = videoFPS;}@Deprecatedpublic CaptureConfiguration(CaptureResolution resolution, CaptureQuality quality, int maxDurationSecs,int maxFilesizeMb) {this(resolution, quality);maxDurationMs = maxDurationSecs * MSEC_TO_SEC;maxFilesizeBytes = maxFilesizeMb * MBYTE_TO_BYTE;}@Deprecatedpublic CaptureConfiguration(int videoWidth, int videoHeight, int bitrate) {this.videoWidth = videoWidth;this.videoHeight = videoHeight;this.bitrate = bitrate;}@Deprecatedpublic 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;}
本文中使用的是:
@Deprecatedpublic 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), // LD
RES_480P(WIDTH_480P, HEIGHT_480P, BITRATE_HQ_480P, BITRATE_MQ_480P, BITRATE_LQ_480P), // SD
RES_720P(WIDTH_720P, HEIGHT_720P, BITRATE_HQ_720P, BITRATE_MQ_720P, BITRATE_LQ_720P), // HD ready
RES_1080P(WIDTH_1080P, HEIGHT_1080P, BITRATE_HQ_1080P, BITRATE_MQ_1080P, BITRATE_LQ_1080P), // HD
RES_1440P(WIDTH_1440P, HEIGHT_1440P, BITRATE_HQ_1440P, BITRATE_MQ_1440P, BITRATE_LQ_1440P), // 2K
RES_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下载:点击打开链接
希望对大家有帮助~!
这篇关于Android录制视频---LandscapeVideoCamera的使用详情及修改的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!