Skip to content

Commit

Permalink
bug fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
salime45 committed Sep 25, 2020
1 parent e3619ec commit 865e670
Showing 1 changed file with 36 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,11 @@ class FlutterScreenRecordingPlugin(

mProjectionManager = registrar.context().applicationContext.getSystemService(Context.MEDIA_PROJECTION_SERVICE) as MediaProjectionManager?

videoName = call.argument("name")
recordAudio = call.argument("audio")
// initMediaRecorder();
videoName = call.argument<String?>("name")
recordAudio = call.argument<Boolean?>("audio")
initMediaRecorder();
startRecordScreen()
//result.success(true)
} catch (e: Exception) {
println("Error onMethodCall startRecordScreen")
println(e.message)
Expand All @@ -111,12 +112,12 @@ class FlutterScreenRecordingPlugin(
}
}

fun calculeResolution(screenSize:Point) {
fun calculeResolution(screenSize: Point) {

val screenRatio : Double = (screenSize.x.toDouble() / screenSize.y.toDouble())
val screenRatio: Double = (screenSize.x.toDouble() / screenSize.y.toDouble())

println(screenSize.x.toString() + " --- " + screenSize.y.toString())
val height : Double = mDisplayWidth / screenRatio;
var height: Double = mDisplayWidth / screenRatio;
println("height - " + height)

mDisplayHeight = height.toInt()
Expand All @@ -132,37 +133,47 @@ class FlutterScreenRecordingPlugin(
println("$mDisplayWidth x $mDisplayHeight")
}

fun startRecordScreen() {
try {
mMediaRecorder?.setVideoSource(MediaRecorder.VideoSource.SURFACE)
if (recordAudio!!) {
mMediaRecorder?.setAudioSource(MediaRecorder.AudioSource.MIC);
mMediaRecorder?.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
mMediaRecorder?.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
} else {
mMediaRecorder?.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4)
}
mMediaRecorder?.setOutputFile("${storePath}${videoName}.mp4")
fun initMediaRecorder() {
mMediaRecorder?.setVideoSource(MediaRecorder.VideoSource.SURFACE)

//mMediaRecorder?.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4)
mMediaRecorder?.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);

if (recordAudio!!) {
mMediaRecorder?.setAudioSource(MediaRecorder.AudioSource.VOICE_RECOGNITION);
mMediaRecorder?.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);//AAC //HE_AAC
mMediaRecorder?.setAudioEncodingBitRate(16 * 44100);
mMediaRecorder?.setAudioSamplingRate(44100);
}

val rotation = (registrar.activity().getSystemService(Context.WINDOW_SERVICE) as WindowManager).defaultDisplay.orientation
mMediaRecorder?.setOrientationHint(rotation * 90)
mMediaRecorder?.setVideoEncoder(MediaRecorder.VideoEncoder.H264)

mMediaRecorder?.setVideoSize(mDisplayWidth, mDisplayHeight)
mMediaRecorder?.setVideoEncoder(MediaRecorder.VideoEncoder.H264)
mMediaRecorder?.setVideoEncodingBitRate(5 * mDisplayWidth * mDisplayHeight)
mMediaRecorder?.setVideoFrameRate(60)
println(mDisplayWidth.toString() + " " + mDisplayHeight);
mMediaRecorder?.setVideoSize(mDisplayWidth, mDisplayHeight)
mMediaRecorder?.setVideoFrameRate(30)

mMediaRecorder?.setOutputFile("${storePath}${videoName}.mp4")

println("file --- " + "${storePath}${videoName}.mp4")

mMediaRecorder?.setVideoEncodingBitRate(5 * mDisplayWidth * mDisplayHeight)
mMediaRecorder?.prepare()
}

fun startRecordScreen() {
try {
//mMediaRecorder?.prepare()

mMediaRecorder?.prepare()
mMediaRecorder?.start()

} catch (e: IOException) {
println("ERR");
Log.d("--INIT-RECORDER", e.message)
println("Error startRecordScreen")
println(e.message)
}

val permissionIntent = mProjectionManager?.createScreenCaptureIntent()
// ActivityCompat.startActivityForResult((registrar.context().applicationContext as FlutterApplication).currentActivity, permissionIntent!!, SCREEN_RECORD_REQUEST_CODE, null)
ActivityCompat.startActivityForResult(registrar.activity(), permissionIntent!!, SCREEN_RECORD_REQUEST_CODE, null)

}
Expand Down

0 comments on commit 865e670

Please sign in to comment.