Skip to content

Commit

Permalink
1.0.7增强兼容性,防止视频尺寸不支持崩溃
Browse files Browse the repository at this point in the history
  • Loading branch information
mabeijianxi committed Oct 25, 2016
1 parent 69a07e1 commit c666005
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 17 deletions.
6 changes: 3 additions & 3 deletions SmallVideoLib/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ android {
defaultConfig {
minSdkVersion 14
targetSdkVersion 22
versionCode 7
versionName "1.0.6"
versionCode 8
versionName "1.0.7"
}

buildTypes {
Expand All @@ -23,7 +23,7 @@ android {
userOrg = 'mabeijianxi'//bintray.com用户名
groupId = 'com.mabeijianxi'//jcenter上的路径
artifactId = 'small-video-record'//项目名称
publishVersion = '1.0.6'//版本号
publishVersion = '1.0.7'//版本号
desc = '利用FFmpeg来小视频录制与压缩处理!'//描述,不重要
website = 'https://github.com/mabeijianxi/small-video-record'//网站,不重要
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ public class MediaRecorderActivity extends Activity implements
*/
public final static String MEDIA_RECORDER_CONFIG_KEY = "media_recorder_config_key";

private boolean GO_HOME;
/**
* @param context
* @param overGOActivityName 录制结束后需要跳转的Activity全类名
Expand Down Expand Up @@ -167,6 +168,7 @@ private void initData() {
MediaRecorderBase.mVideoBitrate=mediaRecorderConfig.getVideoBitrate();
MediaRecorderBase.CAPTURE_THUMBNAILS_TIME=mediaRecorderConfig.getCaptureThumbnailsTime();
MediaRecorderBase.doH264Compress=mediaRecorderConfig.isDoH264Compress();
GO_HOME=mediaRecorderConfig.isGO_HOME();
}

/**
Expand Down Expand Up @@ -581,6 +583,7 @@ public void onEncodeComplete() {
intent.putExtra(MediaRecorderActivity.OUTPUT_DIRECTORY, mMediaObject.getOutputDirectory());
intent.putExtra(MediaRecorderActivity.VIDEO_URI, mMediaObject.getOutputTempTranscodingVideoPath());
intent.putExtra(MediaRecorderActivity.VIDEO_SCREENSHOT, mMediaObject.getOutputVideoThumbPath());
intent.putExtra("go_home",GO_HOME);
startActivity(intent);
} catch (ClassNotFoundException e) {
throw new IllegalArgumentException("需要传入录制完成后跳转的Activity的全类名");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -535,22 +535,22 @@ protected void prepareCameraParaments() {
// mParameters.setPreviewFpsRange(15 * 1000, 20 * 1000);
// TODO 设置浏览尺寸
boolean findWidth = false;
for (int i = 0; i < mSupportedPreviewSizes.size(); i++) {
for (int i = mSupportedPreviewSizes.size() - 1; i >= 0; i--) {
Size size = mSupportedPreviewSizes.get(i);
if (size.height == SMALL_VIDEO_WIDTH) {
if (SMALL_VIDEO_WIDTH == 480) {
mSupportedPreviewWidth = 640;
} else {
mSupportedPreviewWidth = size.width;
}

mSupportedPreviewWidth = size.width;
findWidth = true;
break;
}
}
if (findWidth) {
mParameters.setPreviewSize(mSupportedPreviewWidth, SMALL_VIDEO_WIDTH);
} else {
throw new IllegalArgumentException("传入高度不支持或未找到对应宽度");
if (!findWidth) {
Log.e(getClass().getSimpleName(), "传入高度不支持或未找到对应宽度,请按照要求重新设置,否则会出现一些验证问题");
mSupportedPreviewWidth = 640;
SMALL_VIDEO_WIDTH = 480;
SMALL_VIDEO_HEIGHT = 360;
}
mParameters.setPreviewSize(mSupportedPreviewWidth, SMALL_VIDEO_WIDTH);

// 设置输出视频流尺寸,采样率
mParameters.setPreviewFormat(ImageFormat.NV21);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public final class MediaRecorderConfig implements Parcelable {
*/
private final int captureThumbnailsTime;

private final boolean GO_HOME;

private MediaRecorderConfig(Buidler buidler) {
this.RECORD_TIME_MAX = buidler.RECORD_TIME_MAX;
Expand All @@ -58,8 +59,12 @@ private MediaRecorderConfig(Buidler buidler) {
this.SMALL_VIDEO_WIDTH = buidler.SMALL_VIDEO_WIDTH;
this.VIDEO_BITRATE = buidler.VIDEO_BITRATE;
this.doH264Compress = buidler.doH264Compress;
}
this.GO_HOME=buidler.GO_HOME;

}
public boolean isGO_HOME() {
return GO_HOME;
}
public int getCaptureThumbnailsTime() {
return captureThumbnailsTime;
}
Expand Down Expand Up @@ -111,6 +116,7 @@ protected MediaRecorderConfig(Parcel in) {
VIDEO_BITRATE = in.readInt();
doH264Compress = in.readByte() != 0;
captureThumbnailsTime = in.readInt();
GO_HOME=in.readByte() != 0;
}

public static final Creator<MediaRecorderConfig> CREATOR = new Creator<MediaRecorderConfig>() {
Expand All @@ -136,6 +142,7 @@ public void writeToParcel(Parcel dest, int flags) {
dest.writeInt(VIDEO_BITRATE);
dest.writeByte((byte) (doH264Compress ? 1 : 0));
dest.writeInt(captureThumbnailsTime);
dest.writeInt((byte)(GO_HOME?1:0));
}

public static class Buidler {
Expand Down Expand Up @@ -178,6 +185,8 @@ public static class Buidler {
*/
private int captureThumbnailsTime = 1;

private boolean GO_HOME=false;


public MediaRecorderConfig build() {
return new MediaRecorderConfig(this);
Expand Down Expand Up @@ -265,6 +274,11 @@ public Buidler videoBitrate(int VIDEO_BITRATE) {
this.VIDEO_BITRATE = VIDEO_BITRATE;
return this;
}

public Buidler goHome(boolean GO_HOME) {
this.GO_HOME = GO_HOME;
return this;
}
}

}
4 changes: 2 additions & 2 deletions sample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ android {
applicationId "com.mabeijianxi.smallvideo"
minSdkVersion 14
targetSdkVersion 22
versionCode 7
versionName "1.0.6"
versionCode 8
versionName "1.0.7"
}
buildTypes {
release {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,13 @@ public void go(View c) {
MediaRecorderConfig config = new MediaRecorderConfig.Buidler()
.doH264Compress(true)
.smallVideoWidth(480)
.smallVideoHeight(320)
.smallVideoHeight(360)
.recordTimeMax(6 * 1000)
.maxFrameRate(20)
.minFrameRate(8)
.captureThumbnailsTime(1)
.recordTimeMin((int) (1.5 * 1000))
.goHome(false)
.build();
MediaRecorderActivity.goSmallVideoRecorder(this, SendSmallVideoActivity.class.getName(), config);
}
Expand Down

0 comments on commit c666005

Please sign in to comment.