From 321f62c0369a24e43e3ba398702f0eb013288c25 Mon Sep 17 00:00:00 2001 From: HBiSoft Date: Fri, 21 Feb 2020 15:23:51 +0200 Subject: [PATCH] Fix issue #6 --- .idea/gradle.xml | 8 ++++++++ .../com/hbisoft/hbrecorderexample/MainActivity.java | 2 ++ .../main/java/com/hbisoft/hbrecorder/HBRecorder.java | 12 ++++-------- .../com/hbisoft/hbrecorder/ScreenRecordService.java | 12 ++++++++++-- 4 files changed, 24 insertions(+), 10 deletions(-) diff --git a/.idea/gradle.xml b/.idea/gradle.xml index 2996d53..c6f77c6 100644 --- a/.idea/gradle.xml +++ b/.idea/gradle.xml @@ -8,7 +8,15 @@ diff --git a/app/src/main/java/com/hbisoft/hbrecorderexample/MainActivity.java b/app/src/main/java/com/hbisoft/hbrecorderexample/MainActivity.java index e765152..40d660b 100644 --- a/app/src/main/java/com/hbisoft/hbrecorderexample/MainActivity.java +++ b/app/src/main/java/com/hbisoft/hbrecorderexample/MainActivity.java @@ -30,6 +30,7 @@ import android.widget.Toast; import com.hbisoft.hbrecorder.HBRecorder; +import com.hbisoft.hbrecorder.HBRecorderCodecInfo; import com.hbisoft.hbrecorder.HBRecorderListener; import java.io.File; @@ -312,6 +313,7 @@ private void customSettings() { } } + //NOTE - THIS MIGHT NOT BE SUPPORTED SIZES FOR YOUR DEVICE //Video Dimensions String video_resolution = prefs.getString("key_video_resolution",null); if (video_resolution!=null){ diff --git a/hbrecorder/src/main/java/com/hbisoft/hbrecorder/HBRecorder.java b/hbrecorder/src/main/java/com/hbisoft/hbrecorder/HBRecorder.java index ec86095..a31e968 100644 --- a/hbrecorder/src/main/java/com/hbisoft/hbrecorder/HBRecorder.java +++ b/hbrecorder/src/main/java/com/hbisoft/hbrecorder/HBRecorder.java @@ -52,7 +52,7 @@ public class HBRecorder implements MyListener { public HBRecorder(Context context, HBRecorderListener listener) { this.context = context.getApplicationContext(); this.hbRecorderListener = listener; - getScreenDimensions(); + setScreenDensity(); } /*Set output path*/ @@ -122,17 +122,13 @@ public void setOutputFormat(String format){ outputFormat = format; } - /*Get/Set screen dimensions/resolution - * This is use to determine video bitrate - * */ - private void getScreenDimensions() { + // Set screen densityDpi + private void setScreenDensity() { DisplayMetrics metrics = Resources.getSystem().getDisplayMetrics(); - mScreenWidth = metrics.widthPixels; - mScreenHeight = metrics.heightPixels; mScreenDensity = metrics.densityDpi; } - //Set Custom Dimensions (NOTE - THIS IS NOT IDEAL - It is best to use the devices screen size) + //Set Custom Dimensions (NOTE - YOUR DEVICE MIGHT NOT SUPPORT THE SIZE YOU PASS IT) public void setScreenDimensions(int heightInPX, int widthInPX){ mScreenHeight = heightInPX; mScreenWidth = widthInPX; diff --git a/hbrecorder/src/main/java/com/hbisoft/hbrecorder/ScreenRecordService.java b/hbrecorder/src/main/java/com/hbisoft/hbrecorder/ScreenRecordService.java index 9bae34f..bf4abdf 100755 --- a/hbrecorder/src/main/java/com/hbisoft/hbrecorder/ScreenRecordService.java +++ b/hbrecorder/src/main/java/com/hbisoft/hbrecorder/ScreenRecordService.java @@ -73,8 +73,16 @@ public int onStartCommand(final Intent intent, int flags, int startId) { String notificationButtonText = intent.getStringExtra("notificationButtonText"); mResultCode = intent.getIntExtra("code", -1); mResultData = intent.getParcelableExtra("data"); - mScreenWidth = intent.getIntExtra("width", 720); - mScreenHeight = intent.getIntExtra("height", 1280); + mScreenWidth = intent.getIntExtra("width", 0); + mScreenHeight = intent.getIntExtra("height", 0); + + if (mScreenHeight == 0 || mScreenWidth == 0){ + HBRecorderCodecInfo hbRecorderCodecInfo = new HBRecorderCodecInfo(); + hbRecorderCodecInfo.setContext(this); + mScreenHeight = hbRecorderCodecInfo.getMaxSupportedHeight(); + mScreenWidth = hbRecorderCodecInfo.getMaxSupportedWidth(); + } + mScreenDensity = intent.getIntExtra("density", 1); isVideoHD = intent.getBooleanExtra("quality", true); isAudioEnabled = intent.getBooleanExtra("audio", true);