提交 cb96601c 编写于 作者: xuexiangjys's avatar xuexiangjys 😊

优化代码处理,将视频录制由activity改为fragment

上级 4d9140a4
......@@ -274,7 +274,7 @@ public class MainActivity extends AppCompatActivity {
}
// FFMpegUtils.captureThumbnails("/storage/emulated/0/DCIM/mabeijianxi/1496455533800/1496455533800.mp4", "/storage/emulated/0/DCIM/mabeijianxi/1496455533800/1496455533800.jpg", "1");
MediaRecorderConfig config = new MediaRecorderConfig.Buidler()
MediaRecorderConfig config = new MediaRecorderConfig.Builder()
.fullScreen(needFull)
.smallVideoWidth(needFull ? 0 : Integer.valueOf(width))
.smallVideoHeight(Integer.valueOf(height))
......@@ -284,7 +284,7 @@ public class MainActivity extends AppCompatActivity {
.videoBitrate(Integer.valueOf(bitrate))
.captureThumbnailsTime(1)
.build();
MediaRecorderActivity.goSmallVideoRecorder(this, SendSmallVideoActivity.class.getName(), config);
MediaRecorderActivity.startVideoRecorder(this, SendSmallVideoActivity.class.getName(), config);
}
......@@ -364,8 +364,8 @@ public class MainActivity extends AppCompatActivity {
if (!TextUtils.isEmpty(scale)) {
fScale = Float.valueOf(scale);
}
LocalMediaConfig.Buidler buidler = new LocalMediaConfig.Buidler();
final LocalMediaConfig config = buidler
LocalMediaConfig.Builder builder = new LocalMediaConfig.Builder();
final LocalMediaConfig config = builder
.setVideoPath(_data)
.captureThumbnailsTime(1)
.doH264Compress(compressMode)
......
......@@ -37,6 +37,7 @@ android {
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
compileOnly deps.support.app_compat
}
apply from: "https://raw.githubusercontent.com/xuexiangjys/XUtil/master/JitPackUpload.gradle"
......@@ -45,13 +45,13 @@ public final class LocalMediaConfig implements Parcelable {
private final float scale;
private LocalMediaConfig(Buidler buidler) {
this.captureThumbnailsTime = buidler.captureThumbnailsTime;
this.FRAME_RATE = buidler.FRAME_RATE;
this.compressConfig = buidler.compressConfig;
this.videoAddress = buidler.videoPath;
this.scale = buidler.scale;
this.GO_HOME = buidler.GO_HOME;
private LocalMediaConfig(Builder builder) {
this.captureThumbnailsTime = builder.captureThumbnailsTime;
this.FRAME_RATE = builder.FRAME_RATE;
this.compressConfig = builder.compressConfig;
this.videoAddress = builder.videoPath;
this.scale = builder.scale;
this.GO_HOME = builder.GO_HOME;
}
......@@ -118,7 +118,7 @@ public final class LocalMediaConfig implements Parcelable {
}
public static class Buidler {
public static class Builder {
/**
* 录制后会剪切一帧缩略图并保存,就是取时间轴上这个时间的画面
*/
......@@ -141,7 +141,7 @@ public final class LocalMediaConfig implements Parcelable {
* @param captureThumbnailsTime 会剪切一帧缩略图并保存,就是取时间轴上这个时间的画面
* @return
*/
public Buidler captureThumbnailsTime(int captureThumbnailsTime) {
public Builder captureThumbnailsTime(int captureThumbnailsTime) {
this.captureThumbnailsTime = captureThumbnailsTime;
return this;
}
......@@ -151,23 +151,23 @@ public final class LocalMediaConfig implements Parcelable {
* {@link AutoVBRMode }{@link VBRMode}{@link CBRMode}
* @return
*/
public Buidler doH264Compress(BaseMediaBitrateConfig compressConfig) {
public Builder doH264Compress(BaseMediaBitrateConfig compressConfig) {
this.compressConfig = compressConfig;
return this;
}
public Buidler goHome(boolean GO_HOME) {
public Builder goHome(boolean GO_HOME) {
this.GO_HOME = GO_HOME;
return this;
}
public Buidler setFramerate(int MAX_FRAME_RATE) {
public Builder setFramerate(int MAX_FRAME_RATE) {
this.FRAME_RATE = MAX_FRAME_RATE;
return this;
}
public Buidler setVideoPath(String videoPath) {
public Builder setVideoPath(String videoPath) {
this.videoPath = videoPath;
return this;
}
......@@ -176,7 +176,7 @@ public final class LocalMediaConfig implements Parcelable {
* @param scale 大于1,否者无效
* @return
*/
public Buidler setScale(float scale) {
public Builder setScale(float scale) {
if (scale <= 1) {
this.scale = 1;
} else {
......
......@@ -64,21 +64,22 @@ public final class MediaRecorderConfig implements Parcelable {
private final boolean GO_HOME;
private MediaRecorderConfig(Buidler buidler) {
this.FULL_SCREEN = buidler.FULL_SCREEN;
this.RECORD_TIME_MAX = buidler.RECORD_TIME_MAX;
this.RECORD_TIME_MIN = buidler.RECORD_TIME_MIN;
this.MAX_FRAME_RATE = buidler.MAX_FRAME_RATE;
this.captureThumbnailsTime = buidler.captureThumbnailsTime;
this.MIN_FRAME_RATE = buidler.MIN_FRAME_RATE;
this.SMALL_VIDEO_HEIGHT = buidler.SMALL_VIDEO_HEIGHT;
this.SMALL_VIDEO_WIDTH = buidler.SMALL_VIDEO_WIDTH;
this.VIDEO_BITRATE = buidler.VIDEO_BITRATE;
this.GO_HOME = buidler.GO_HOME;
public static MediaRecorderConfig newInstance() {
return new Builder().build();
}
private MediaRecorderConfig(Builder builder) {
this.FULL_SCREEN = builder.fullscreen;
this.RECORD_TIME_MAX = builder.recordTimeMax;
this.RECORD_TIME_MIN = builder.recordTimeMin;
this.MAX_FRAME_RATE = builder.maxFrameRate;
this.captureThumbnailsTime = builder.captureThumbnailsTime;
this.MIN_FRAME_RATE = builder.minFrameRate;
this.SMALL_VIDEO_HEIGHT = builder.smallVideoHeight;
this.SMALL_VIDEO_WIDTH = builder.smallVideoWidth;
this.VIDEO_BITRATE = builder.videoBitrate;
this.GO_HOME = builder.goHome;
}
protected MediaRecorderConfig(Parcel in) {
FULL_SCREEN = in.readByte() != 0;
......@@ -105,7 +106,7 @@ public final class MediaRecorderConfig implements Parcelable {
}
};
public boolean isGO_HOME() {
public boolean isGoHome() {
return GO_HOME;
}
......@@ -142,7 +143,6 @@ public final class MediaRecorderConfig implements Parcelable {
return SMALL_VIDEO_WIDTH;
}
public int getVideoBitrate() {
return VIDEO_BITRATE;
}
......@@ -166,47 +166,74 @@ public final class MediaRecorderConfig implements Parcelable {
dest.writeByte((byte) (GO_HOME ? 1 : 0));
}
public static Builder newBuilder() {
return new Builder();
}
/**
* 默认录制最长时间
*/
public static final int DEFAULT_RECORD_TIME_MAX = 6 * 1000;
/**
* 默认录制最短时间
*/
public static final int DEFAULT_RECORD_TIME_MIN = (int) (1.5 * 1000);
/**
* 默认小视频高度
*/
public static final int DEFAULT_SMALL_VIDEO_HEIGHT = 480;
/**
* 默认小视频宽度
*/
public static final int DEFAULT_SMALL_VIDEO_WIDTH = 360;
/**
* 默认最大帧率
*/
public static final int DEFAULT_SMALL_MAX_FRAME_RATE = 20;
/**
* 默认最小帧率
*/
public static final int DEFAULT_SMALL_MIN_FRAME_RATE = 8;
public static class Buidler {
public static class Builder {
/**
* 录制时间
*/
private int RECORD_TIME_MAX = 6 * 1000;
private int recordTimeMax = DEFAULT_RECORD_TIME_MAX;
private int recordTimeMin = DEFAULT_RECORD_TIME_MIN;
/**
* 小视频高度,TODO 注意:宽度不能随意穿,需要传送手机摄像头手支持录制的视频高度,注意是高度(因为会选择,具体原因不多解析)。
* 获取摄像头所支持的尺寸的方式是{@link android.graphics.Camera #getSupportedPreviewSizes()}
* 一般支持的尺寸的高度有:240、480、720、1080等,具体值请用以上方法获取
*/
private int SMALL_VIDEO_HEIGHT = 480;
private int smallVideoHeight = DEFAULT_SMALL_VIDEO_HEIGHT;
/**
* 小视频宽度
*/
private int SMALL_VIDEO_WIDTH = 360;
private int smallVideoWidth = DEFAULT_SMALL_VIDEO_WIDTH;
/**
* 最大帧率
*/
private int MAX_FRAME_RATE = 20;
private int maxFrameRate = DEFAULT_SMALL_MAX_FRAME_RATE;
/**
* 最小帧率
*/
private int MIN_FRAME_RATE = 8;
private int minFrameRate = DEFAULT_SMALL_MIN_FRAME_RATE;
/**
* 视频码率//todo 注意传入>0的值后码率模式将从VBR变成CBR
*/
private int VIDEO_BITRATE;
private int videoBitrate;
/**
* 录制后会剪切一帧缩略图并保存,就是取时间轴上这个时间的画面
*/
private int captureThumbnailsTime = 1;
private boolean goHome = false;
private boolean GO_HOME = false;
public int RECORD_TIME_MIN = (int) (1.5 * 1000);
private boolean FULL_SCREEN = false;
private boolean fullscreen = false;
public MediaRecorderConfig build() {
......@@ -217,18 +244,17 @@ public final class MediaRecorderConfig implements Parcelable {
* @param captureThumbnailsTime 录制后会剪切一帧缩略图并保存,就是取时间轴上这个时间的画面
* @return
*/
public Buidler captureThumbnailsTime(int captureThumbnailsTime) {
public Builder captureThumbnailsTime(int captureThumbnailsTime) {
this.captureThumbnailsTime = captureThumbnailsTime;
return this;
}
/**
* @param MAX_FRAME_RATE 最大帧率(与视频清晰度、大小息息相关)
* @return
*/
public Buidler maxFrameRate(int MAX_FRAME_RATE) {
this.MAX_FRAME_RATE = MAX_FRAME_RATE;
public Builder maxFrameRate(int MAX_FRAME_RATE) {
this.maxFrameRate = MAX_FRAME_RATE;
return this;
}
......@@ -236,8 +262,8 @@ public final class MediaRecorderConfig implements Parcelable {
* @param MIN_FRAME_RATE 最小帧率(与视频清晰度、大小息息相关)
* @return
*/
public Buidler minFrameRate(int MIN_FRAME_RATE) {
this.MIN_FRAME_RATE = MIN_FRAME_RATE;
public Builder minFrameRate(int MIN_FRAME_RATE) {
this.minFrameRate = MIN_FRAME_RATE;
return this;
}
......@@ -245,8 +271,8 @@ public final class MediaRecorderConfig implements Parcelable {
* @param RECORD_TIME_MAX 录制时间
* @return
*/
public Buidler recordTimeMax(int RECORD_TIME_MAX) {
this.RECORD_TIME_MAX = RECORD_TIME_MAX;
public Builder recordTimeMax(int RECORD_TIME_MAX) {
this.recordTimeMax = RECORD_TIME_MAX;
return this;
}
......@@ -254,8 +280,8 @@ public final class MediaRecorderConfig implements Parcelable {
* @param RECORD_TIME_MIN 最少录制时间
* @return
*/
public Buidler recordTimeMin(int RECORD_TIME_MIN) {
this.RECORD_TIME_MIN = RECORD_TIME_MIN;
public Builder recordTimeMin(int RECORD_TIME_MIN) {
this.recordTimeMin = RECORD_TIME_MIN;
return this;
}
......@@ -266,8 +292,8 @@ public final class MediaRecorderConfig implements Parcelable {
* 一般支持的尺寸的高度有:240、480、720、1080等,具体值请用以上方法获取
* @return
*/
public Buidler smallVideoHeight(int SMALL_VIDEO_HEIGHT) {
this.SMALL_VIDEO_HEIGHT = SMALL_VIDEO_HEIGHT;
public Builder smallVideoHeight(int SMALL_VIDEO_HEIGHT) {
this.smallVideoHeight = SMALL_VIDEO_HEIGHT;
return this;
}
......@@ -275,8 +301,8 @@ public final class MediaRecorderConfig implements Parcelable {
* @param SMALL_VIDEO_WIDTH
* @return
*/
public Buidler smallVideoWidth(int SMALL_VIDEO_WIDTH) {
this.SMALL_VIDEO_WIDTH = SMALL_VIDEO_WIDTH;
public Builder smallVideoWidth(int SMALL_VIDEO_WIDTH) {
this.smallVideoWidth = SMALL_VIDEO_WIDTH;
return this;
}
......@@ -284,18 +310,18 @@ public final class MediaRecorderConfig implements Parcelable {
* @param VIDEO_BITRATE 视频码率
* @return
*/
public Buidler videoBitrate(int VIDEO_BITRATE) {
this.VIDEO_BITRATE = VIDEO_BITRATE;
public Builder videoBitrate(int VIDEO_BITRATE) {
this.videoBitrate = VIDEO_BITRATE;
return this;
}
public Buidler goHome(boolean GO_HOME) {
this.GO_HOME = GO_HOME;
public Builder goHome(boolean GO_HOME) {
this.goHome = GO_HOME;
return this;
}
public Buidler fullScreen(boolean full) {
this.FULL_SCREEN = full;
public Builder fullScreen(boolean full) {
this.fullscreen = full;
return this;
}
}
......
<?xml version="1.0" encoding="utf-8"?><!--
~ Copyright (C) 2018 xuexiangjys(xuexiangjys@163.com)
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/transparent">
android:orientation="vertical">
<FrameLayout
android:id="@+id/fl_record_container"
android:layout_width="match_parent"
android:layout_height="match_parent">
<SurfaceView
android:id="@+id/record_preview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="49dp" />
</FrameLayout>
<RelativeLayout
android:id="@+id/title_layout"
android:layout_width="match_parent"
android:layout_height="49dp"
android:background="@color/xvideo_actionbar_bg_color"
android:gravity="center_vertical">
<ImageView
android:id="@+id/title_back"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="10dip"
android:padding="10dip"
android:src="@drawable/xvideo_cancel_normal" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="49dip"
android:layout_alignParentRight="true"
android:gravity="end|center_vertical"
android:orientation="horizontal">
<CheckBox
android:id="@+id/record_camera_led"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/xvideo_camera_flash_led_selector"
android:button="@null"
android:textColor="@android:color/white" />
<CheckBox
android:id="@+id/record_camera_switcher"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="15dip"
android:layout_marginRight="10dp"
android:background="@drawable/xvideo_camera_switch_selector"
android:button="@null" />
<ImageView
android:id="@+id/title_next"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="5dip"
android:padding="10dip"
android:src="@drawable/xvideo_next_seletor"
android:visibility="gone" />
</LinearLayout>
</RelativeLayout>
<com.xuexiang.xvideo.ProgressView
android:id="@+id/record_progress"
android:layout_width="match_parent"
android:layout_height="5dp"
android:layout_below="@+id/title_layout" />
<!-- camera_bottom_bg -->
<RelativeLayout
android:id="@+id/bottom_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/record_progress"
android:layout_marginTop="300dip"
android:background="@color/xvideo_actionbar_bg_color">
<CheckedTextView
android:id="@+id/record_delete"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="18dip"
android:background="@drawable/xvideo_delete_selector"
android:button="@null"
android:visibility="gone" />
<TextView
android:id="@+id/record_controller"
android:layout_width="108dp"
android:layout_height="108dp"
android:layout_centerInParent="true"
android:background="@drawable/xvideo_small_video_shoot"
android:gravity="center"
android:text="按住拍"
android:textColor="@color/xvideo_camera_progress_three"
android:textSize="16sp" />
</RelativeLayout>
android:layout_height="match_parent" />
</RelativeLayout>
\ No newline at end of file
</LinearLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?><!--
~ Copyright (C) 2018 xuexiangjys(xuexiangjys@163.com)
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/transparent">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<SurfaceView
android:id="@+id/record_preview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="49dp" />
</FrameLayout>
<RelativeLayout
android:id="@+id/title_layout"
android:layout_width="match_parent"
android:layout_height="49dp"
android:background="@color/xvideo_actionbar_bg_color"
android:gravity="center_vertical">
<ImageView
android:id="@+id/title_back"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="10dip"
android:padding="10dip"
android:src="@drawable/xvideo_cancel_normal" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="49dip"
android:layout_alignParentRight="true"
android:gravity="end|center_vertical"
android:orientation="horizontal">
<CheckBox
android:id="@+id/record_camera_led"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/xvideo_camera_flash_led_selector"
android:button="@null"
android:textColor="@android:color/white" />
<CheckBox
android:id="@+id/record_camera_switcher"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="15dip"
android:layout_marginRight="10dp"
android:background="@drawable/xvideo_camera_switch_selector"
android:button="@null" />
<ImageView
android:id="@+id/title_next"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="5dip"
android:padding="10dip"
android:src="@drawable/xvideo_next_seletor"
android:visibility="gone" />
</LinearLayout>
</RelativeLayout>
<com.xuexiang.xvideo.ProgressView
android:id="@+id/record_progress"
android:layout_width="match_parent"
android:layout_height="5dp"
android:layout_below="@+id/title_layout" />
<!-- camera_bottom_bg -->
<RelativeLayout
android:id="@+id/bottom_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/record_progress"
android:layout_marginTop="300dip"
android:background="@color/xvideo_actionbar_bg_color">
<CheckedTextView
android:id="@+id/record_delete"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="18dip"
android:background="@drawable/xvideo_delete_selector"
android:button="@null"
android:visibility="gone" />
<TextView
android:id="@+id/record_controller"
android:layout_width="108dp"
android:layout_height="108dp"
android:layout_centerInParent="true"
android:background="@drawable/xvideo_small_video_shoot"
android:gravity="center"
android:text="按住拍"
android:textColor="@color/xvideo_camera_progress_three"
android:textSize="16sp" />
</RelativeLayout>
</RelativeLayout>
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册