HBiSoft / HBRecorder

Lightweight screen recording Android library
MIT License
402 stars 137 forks source link

Android 14 compatibility #166

Closed noobiewoobie closed 3 weeks ago

noobiewoobie commented 3 months ago

I have implemented our library in my app. Everything works well till android 13. But for android 14, it is unable to record with the following error.

Recording error - Code: 100, Reason: java.lang.IllegalStateException: Must register a callback before starting capture, to manage resources in response to MediaProjection states. at android.media.projection.MediaProjection.createVirtualDisplay(MediaProjection.java:206) at com.hbisoft.hbrecorder.ScreenRecordService.initVirtualDisplay(ScreenRecordService.java:563) at com.hbisoft.hbrecorder.ScreenRecordService.onStartCommand(ScreenRecordService.java:273) at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:4821) at android.app.ActivityThread.-$$Nest$mhandleServiceArgs(Unknown Source:0) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2289) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loopOnce(Looper.java:205) at android.os.Looper.loop(Looper.java:294) at android.app.ActivityThread.main(ActivityThread.java:8177) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:552) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:971)

I copy pasted your exact implementation and still facing this error. This issue is only happening for android 14. My target sdk is same as yours 34, I have added same permissions as you , I have followed everything as you for starting the recording and still facing this issue.

CodeWithTamim commented 3 months ago

Fixed issue. Check fork on my profile. Make sure to give it a start haha.

HBiSoft commented 3 weeks ago

Fixed in 3.0.4

Apologies for taking so long to fix this.

noobiewoobie commented 3 weeks ago

I will test it. Also, here's one more issue. It's related to setting notification icon. Strangely I cannot understand the relation between setting notification small icon while setting the recorder but if I set any icon from my side then when recording is started it works fine but when you stop the recording it fails to generate a playable video file. The file generated has extension of mp4 but you cannot play it. I tried all video configurations and it happened with all of them. So I was confused about why this is happening then I tested as follows and it works fine now.

  private fun recordingSettings() {
        hbRecorder?.let {
            it.setAudioBitrate(128000)
            it.setAudioSamplingRate(44100)
            it.recordHDVideo(false)
            it.isAudioEnabled(true)
//            it.setNotificationSmallIcon(R.drawable.logo)
            it.setNotificationTitle(getString(R.string.stop_recording_notification_title))
            it.setNotificationDescription(getString(R.string.stop_recording_notification_message))
        }

    }