question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Could not start video recording...

See original GitHub issue

Hi, I was testing your very interesting library with a simple code provided in the README :

public class ScreenRecorder extends AppCompatActivity implements HBRecorderListener {

    private static final int SCREEN_RECORD_REQUEST_CODE = 12345;
    HBRecorder hbRecorder;

    Button button10, button11;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.screen_recorder);

        button10 = (Button) findViewById(R.id.button10);
        button11 = (Button) findViewById(R.id.button11);


        button10.setOnClickListener(new View.OnClickListener() {
            @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
            @Override
            public void onClick(View v) {
                startRecordingScreen();
            }
        });

        button11.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                hbRecorder.stopScreenRecording();
            }
        });

        //Init HBRecorder
        hbRecorder = new HBRecorder(this, this);
    }

    @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
    private void startRecordingScreen() {
        MediaProjectionManager mediaProjectionManager = (MediaProjectionManager) getSystemService(Context.MEDIA_PROJECTION_SERVICE);
        Intent permissionIntent = mediaProjectionManager != null ? mediaProjectionManager.createScreenCaptureIntent() : null;
        startActivityForResult(permissionIntent, SCREEN_RECORD_REQUEST_CODE);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == SCREEN_RECORD_REQUEST_CODE) {
            if (resultCode == RESULT_OK) {
                Toast.makeText(this, "Authorization granted", Toast.LENGTH_LONG).show();
                //Start screen recording
                hbRecorder.startScreenRecording(data, resultCode, this);

            }
        }
    }

    @Override
    public void HBRecorderOnComplete() {

    }

    @Override
    public void HBRecorderOnError(int errorCode, String reason) {

    }
}

But when I try to start the recording, I see the Recording Prompt message from Android, I click on Start Now and the app crash.

On the Log I can see the following errors :

2020-05-03 22:26:19.854 23343-23343/fr.gooddev.totalspy E/MediaRecorder: SurfaceMediaSource could not be initialized!
2020-05-03 22:26:19.855 23343-23343/fr.gooddev.totalspy E/MediaRecorder: start called in an invalid state: 4
2020-05-03 22:26:19.902 23343-23343/fr.gooddev.totalspy D/AndroidRuntime: Shutting down VM
2020-05-03 22:26:19.903 23343-23343/fr.gooddev.totalspy E/AndroidRuntime: FATAL EXCEPTION: main
    Process: fr.gooddev.totalspy, PID: 23343
    java.lang.RuntimeException: Unable to stop service com.hbisoft.hbrecorder.ScreenRecordService@c2e5f75: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.media.projection.MediaProjection.stop()' on a null object reference
        at android.app.ActivityThread.handleStopService(ActivityThread.java:4136)
        at android.app.ActivityThread.access$1900(ActivityThread.java:219)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1896)
        at android.os.Handler.dispatchMessage(Handler.java:107)
        at android.os.Looper.loop(Looper.java:214)
        at android.app.ActivityThread.main(ActivityThread.java:7356)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
     Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.media.projection.MediaProjection.stop()' on a null object reference
        at com.hbisoft.hbrecorder.ScreenRecordService.resetAll(ScreenRecordService.java:421)
        at com.hbisoft.hbrecorder.ScreenRecordService.onDestroy(ScreenRecordService.java:407)
        at android.app.ActivityThread.handleStopService(ActivityThread.java:4116)
        at android.app.ActivityThread.access$1900(ActivityThread.java:219) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1896) 
        at android.os.Handler.dispatchMessage(Handler.java:107) 
        at android.os.Looper.loop(Looper.java:214) 
        at android.app.ActivityThread.main(ActivityThread.java:7356) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930) 

I am using the last version of your Library because I just downloaded it from Gradle.

I tried on an Android 10 SDK 29 on an emulator of a Google Pixel 3 XL.

If you need more infos, I can provide it.

Sincerely, Charles BEL

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:13 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
HBiSoftcommented, May 6, 2020

I have migrated the project to Android 10 (API 29). Here is the release.

0reactions
HBiSoftcommented, May 9, 2020

@osfunapps Just to clarify one thing - You should not be getting a crash even if you use getExternalStoragePublicDirectory() because I added android:requestlegacyexternalstorage="true" in the manifest. I tested on a Google Pixel 3XL, running Android 10 and I was able to use getExternalStoragePublicDirectory.

If you did get a crash, please let me know.


As the documentation says:

To improve user privacy, direct access to shared/external storage devices is deprecated. When an app targets Build.VERSION_CODES.Q, the path returned from this method is no longer directly accessible to apps.

So, it doesn’t say that we cannot use getExternalStoragePublicDirectory when targeting Android 10>. It says that the path returned from this method is no longer directly accessible. But by adding android:requestlegacyexternalstorage="true", we can access the path.

For more info, have a look at my question/answer.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Fix Can't Play Recorded Video? - Wondershare Repairit
The major reason why your recorded videos refuse to play is that they have been corrupted. Corruption, in turn, arise from different causes....
Read more >
NotReadableError: could not start video source - Google Groups
I am trying to develop Video Recording from Front as well as Rear Camera using WebRTC. Front camera recording & saving video works...
Read more >
I can't record videos in my phone. How can I fix it? - Quora
Restart/Reboot your device. · Clear cache on your Android phone. · Uninstall insecure apps on your mobile. · Install VLC player…… I find...
Read more >
Cannot record Video Error Fixed - YouTube
Your browser can't play this video. Learn more. Switch camera.
Read more >
Could not start video source in Javascript webcam recorder ...
Another potential explanation is that another process is using the video camera at the same time. Have you verified that your webcam is...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found