Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RuntimeException: stop failed after recording is completed #26

Closed
sagrawal31 opened this issue Feb 29, 2020 · 85 comments
Closed

RuntimeException: stop failed after recording is completed #26

sagrawal31 opened this issue Feb 29, 2020 · 85 comments

Comments

@sagrawal31
Copy link

sagrawal31 commented Feb 29, 2020

Description

I'm using the latest master 1bf79f9 to run the app locally for testing and surprised to see this isn't working.

As soon as the 20s is completed (or even I manually submit the recording), an exception is being thrown:

D/CameraFullscreenRecorderActivity: Recorder. RecordingProgress:19000
D/CameraFullscreenRecorderActivity: Recorder. microphoneHealth:BAD
D/CameraFullscreenRecorderActivity: Recorder. RecordingProgress:20000
D/CameraFullscreenRecorderActivity: Recorder. microphoneHealth:MODERATE
D/ZRecorder$Builder: onInfo. mr:com.ziggeo.androidsdk.recorder.ZRecorder@8d65d01 
    What:800
    Extra:0
I/MediaRecorderJNI: stop
E/MediaRecorder: stop failed: -1007
D/AndroidRuntime: Shutting down VM
E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.ziggeo.androidsdk.demo, PID: 11867
    java.lang.RuntimeException: stop failed.
        at android.media.MediaRecorder._stop(Native Method)
        at android.media.MediaRecorder.stop(MediaRecorder.java:1378)
        at com.ziggeo.androidsdk.widgets.cameraview.CameraViewImpl.releaseMediaRecorder(CameraViewImpl.java:264)
        at com.ziggeo.androidsdk.widgets.cameraview.Camera2Api23.releaseMediaRecorder(Camera2Api23.java:32)
        at com.ziggeo.androidsdk.widgets.cameraview.Camera2.stopRecording(Camera2.java:302)
        at com.ziggeo.androidsdk.widgets.cameraview.Camera2.lambda$prepareMediaRecorder$3$Camera2(Camera2.java:831)
        at com.ziggeo.androidsdk.widgets.cameraview.-$$Lambda$Camera2$hdojrmf2WsZ_VyKq2h4wIE2i4VA.onInfo(Unknown Source:2)
        at com.ziggeo.androidsdk.recorder.ZRecorder$Builder.lambda$build$0$ZRecorder$Builder(ZRecorder.java:133)
        at com.ziggeo.androidsdk.recorder.-$$Lambda$ZRecorder$Builder$RWH90Gu1RcipHZx_2oCneulCrkw.onInfo(Unknown Source:2)
        at android.media.MediaRecorder$EventHandler.handleMessage(MediaRecorder.java:1706)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:214)
        at android.app.ActivityThread.main(ActivityThread.java:7081)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:494)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:965)
W/System.err: java.lang.RuntimeException: stop failed.
        at android.media.MediaRecorder._stop(Native Method)
        at android.media.MediaRecorder.stop(MediaRecorder.java:1378)
        at com.ziggeo.androidsdk.widgets.cameraview.CameraViewImpl.releaseMediaRecorder(CameraViewImpl.java:264)
        at com.ziggeo.androidsdk.widgets.cameraview.Camera2Api23.releaseMediaRecorder(Camera2Api23.java:32)
        at com.ziggeo.androidsdk.widgets.cameraview.Camera2.stopRecording(Camera2.java:302)
        at com.ziggeo.androidsdk.widgets.cameraview.Camera2.lambda$prepareMediaRecorder$3$Camera2(Camera2.java:831)
W/System.err:     at com.ziggeo.androidsdk.widgets.cameraview.-$$Lambda$Camera2$hdojrmf2WsZ_VyKq2h4wIE2i4VA.onInfo(Unknown Source:2)
        at com.ziggeo.androidsdk.recorder.ZRecorder$Builder.lambda$build$0$ZRecorder$Builder(ZRecorder.java:133)
        at com.ziggeo.androidsdk.recorder.-$$Lambda$ZRecorder$Builder$RWH90Gu1RcipHZx_2oCneulCrkw.onInfo(Unknown Source:2)
        at android.media.MediaRecorder$EventHandler.handleMessage(MediaRecorder.java:1706)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:214)
        at android.app.ActivityThread.main(ActivityThread.java:7081)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:494)
W/System.err:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:965)

I even tried upgrading the dependency from 0.82.0 to com.github.ZiggeoJitpackService:Android-SDK:0.83.0_rc4 but it also has the same issue.

Environment

  • OS: macOS Catalina
  • Android version: 9
  • Device: Samsung J6
@sagrawal31
Copy link
Author

sagrawal31 commented Feb 29, 2020

Also, I'm not sure why the version 0.82.1 is not available here https://jitpack.io/#ZiggeoJitpackService/Android-SDK?

@sagrawal31
Copy link
Author

@3akat
Copy link
Contributor

3akat commented Feb 29, 2020

Hi @sagrawal31!
Thanks for reporting it, will take a look shortly.

@sagrawal31
Copy link
Author

Thank you @3akat for the reply.

Wanted to update, not sure why but the same app works fine in an Emulator running Android 8.

@sagrawal31
Copy link
Author

Any update here guys? We are eagerly waiting for a fix/solution/workaround.

@Bane-D
Copy link
Contributor

Bane-D commented Mar 3, 2020

Hi Shashank,

My colleague is looking into this. As soon as there is an update he will push it up and update you that it is available. :)

@3akat
Copy link
Contributor

3akat commented Mar 3, 2020

Hi @sagrawal31, thank you for the detailed description, but I was not able to reproduce the issue on my devices and emulators. Looks like the issue is specific to a Samsung device, I'm trying to understand what's going on.
The link you've shared is actually a workaround for the symptom (the crash). The actual reason is that the recording seems not starting on your device for some reason.
Doing my best to reproduce the issue and fix it ASAP.

@sagrawal31
Copy link
Author

Hi @3akat I'm not really sure what's happening in the Samsung device. This device is the latest and only a year old. So this shouldn't be a problem.

What is the next step are you taking to figure out the problem? Do you need something from my side?
I will be happy to do it.

@sagrawal31
Copy link
Author

@3akat I have been doing the research about this and I got this https://stackoverflow.com/questions/52084401/android-mediarecorder-not-working-in-some-devices

To help you out (and ultimately, to help myself 😃), can you let me know a way that I can set mediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB); somewhere in the code?

@sagrawal31
Copy link
Author

This is just my guesswork, so please feel free to say no if you are confident that this won't work :)

@sagrawal31
Copy link
Author

I literally have no knowledge of this media/camera thing but I can see that the audio encoder is set to 3 i.e. MediaRecorder.AudioEncoder.AAC in ZRecorder.java:

image

So can you release a snapshot version which gives us the ability to customize the audio encoder and then I can change & try in my Samsung device?

@sagrawal31
Copy link
Author

@sagrawal31
Copy link
Author

Another thread which might jog your mind react-native-audio-toolkit/react-native-audio-toolkit#149

@3akat
Copy link
Contributor

3akat commented Mar 3, 2020

Yup, that could be the cause. My main goal now is to reproduce the issue before fixing it. I wasn't able to find the J6 device, but I will test the app on some other Samsungs with android 8 and 9.
Meanwhile, I'll add ability to configure the audio encoder and you'll be able to try it by yourself :)

@sagrawal31
Copy link
Author

Sure, @3akat let me know once you released it. I'll try it out.

@3akat
Copy link
Contributor

3akat commented Mar 3, 2020

@sagrawal31, I've pushed the 0.82.2, please take a look :)
You can set encoder in RecorderConfig object using the following
.audioEncoder(MediaRecorder.AudioEncoder.AMR_NB)

@sagrawal31
Copy link
Author

Hi @3akat, thank you for releasing the version. I added .audioEncoder(MediaRecorder.AudioEncoder.AMR_NB) and verified with breakpoints that this value is being set in ZRecorder.java but the behaviour is still the same.

I even tried all other AudioEncoder i.e. AMR_WB, HE_AAC but the problem still persist.

@3akat
Copy link
Contributor

3akat commented Mar 3, 2020

So that means the issue is not in the audio encoder, thanks for the help :)
Will try to repeat the issue on my devices and fix. I will let you know as soon as the update will be ready.

@sagrawal31
Copy link
Author

sagrawal31 commented Mar 3, 2020

There are two types of behaviours:

When only MediaRecorder.AudioEncoder.AMR_NB is set

image

In this case, as soon as I start recording the video, an exception is thrown:

03-03 17:36:33.154  4108  4108 E AndroidRuntime: Process: com.ziggeo.androidsdk.demo, PID: 4108
03-03 17:36:33.154  4108  4108 E AndroidRuntime: java.lang.IllegalStateException
03-03 17:36:33.154  4108  4108 E AndroidRuntime: 	at android.media.MediaRecorder._start(Native Method)
03-03 17:36:33.154  4108  4108 E AndroidRuntime: 	at android.media.MediaRecorder.start(MediaRecorder.java:1348)
03-03 17:36:33.154  4108  4108 E AndroidRuntime: 	at com.ziggeo.androidsdk.widgets.cameraview.Camera2$4.onConfigured(Camera2.java:590)
03-03 17:36:33.154  4108  4108 E AndroidRuntime: 	at android.hardware.camera2.impl.CallbackProxies$SessionStateCallbackProxy.lambda$onConfigured$0(CallbackProxies.java:53)
03-03 17:36:33.154  4108  4108 E AndroidRuntime: 	at android.hardware.camera2.impl.-$$Lambda$CallbackProxies$SessionStateCallbackProxy$soW0qC12Osypoky6AfL3P2-TeDw.run(Unknown Source:4)
03-03 17:36:33.154  4108  4108 E AndroidRuntime: 	at android.os.Handler.handleCallback(Handler.java:873)
03-03 17:36:33.154  4108  4108 E AndroidRuntime: 	at android.os.Handler.dispatchMessage(Handler.java:99)
03-03 17:36:33.154  4108  4108 E AndroidRuntime: 	at android.os.Looper.loop(Looper.java:214)
03-03 17:36:33.154  4108  4108 E AndroidRuntime: 	at android.app.ActivityThread.main(ActivityThread.java:7081)
03-03 17:36:33.154  4108  4108 E AndroidRuntime: 	at java.lang.reflect.Method.invoke(Native Method)

And video freezes in the recording (recording is added below in zip).

20200303_173755_edited.mp4.zip

When audioSampleRate is set along with MediaRecorder.AudioEncoder.AMR_NB

I added this based on this answer here https://stackoverflow.com/a/46813129/2405040

image

In this case, the recording starts (as we can see in the timer) but video freezes and as soon as we stop the recording (or 20s is finished), the original exception is thrown.

Can't record this video in this case. Maybe recorder conflicting with the demo app.

@sagrawal31
Copy link
Author

So that means the issue is not in the audio encoder, thanks for the help :)
Will try to repeat the issue on my devices and fix. I will let you know as soon as the update will be ready.

Not really sure. But my concern is that why the camera freezes as soon as we start the recording. Maybe it's something about the video?

@3akat
Copy link
Contributor

3akat commented Mar 3, 2020

So that means the issue is not in the audio encoder, thanks for the help :)
Will try to repeat the issue on my devices and fix. I will let you know as soon as the update will be ready.

Not really sure. But my concern is that why the camera freezes as soon as we start the recording. Maybe it's something about the video?

freezing is actually the most common case when the app crashes during recording. In other words if anything bad happens - the video will freeze or blackout

@sagrawal31
Copy link
Author

Agreed. But this is true for the first case when there is a crash during recording. But in the 2nd case, the recording starts successfully (with camera screen freeze) and 20s timer keeps running on the top but an exception is not thrown unless I press the stop button to pause the recording.

@sagrawal31
Copy link
Author

And according to the documentation:

Note that a RuntimeException is intentionally thrown to the application, if no valid audio/video data has been received when stop() is called. This happens if stop() is called immediately after start(). The failure lets the application take action accordingly to clean up the output file (delete the output file, for instance), since the output file is not properly constructed when this happens.

Which is true in our case because even after the timer runs for 20 seconds, no video was recorded (since the camera was frozen) and when we stop it, it throws the RuntimeException.

Is this helps? I don't have much knowledge but just trying to be your help 😃

@sagrawal31
Copy link
Author

@3akat I managed to create a video for you to demonstrate the actual problem that I'm trying to explain as 2nd scenario. It's there in YouTube https://youtu.be/2jtqFrlUqEM

You will see that the timer runs on the top-right corner but the app crashes when the timer ends (or when we manually stop the recording).

@3akat
Copy link
Contributor

3akat commented Mar 3, 2020

Thanks for sharing this! Will take a look.

@3akat
Copy link
Contributor

3akat commented Mar 3, 2020

Hi @sagrawal31, I've tried testing the app on three different Samsung devices - no issues. Tomorrow I'll try to get more.
Meanwhile could you please try to reboot your device? One of our customers also had some weird issue, but it disappeared after rebooting.

@sagrawal31
Copy link
Author

Hi @3akat I have tried restarting the device in the past and just after seeing this comment, I restarted it after proper shutdown but the same issue 😞

@Bane-D
Copy link
Contributor

Bane-D commented Mar 4, 2020

Just jumping in Shashank, is your device maybe jailbroken?

@sagrawal31
Copy link
Author

sagrawal31 commented Mar 4, 2020 via email

@sagrawal31
Copy link
Author

I even tried turning off the "Developer Options" from the Settings.

@sagrawal31
Copy link
Author

Thank you, @3akat

After you clarified the issue, I Googled about camera2 API integration in Samsung and I saw a lot of posts like https://r2.community.samsung.com/t5/Galaxy-J/Samsung-please-enable-camera-2-API-on-Samsung-galaxy-j6/td-p/1801370

@3akat
Copy link
Contributor

3akat commented Mar 17, 2020

Yeah, as I said looks like device doesn't support Camera2

@sagrawal31
Copy link
Author

Thank you @3akat we are testing this in all devices and will update you with that.

@3akat
Copy link
Contributor

3akat commented Mar 18, 2020

Hi @sagrawal31, I have tested on J5. Unfortunately I was not able to reproduce the crash, but the preview was not working and the recording was not starting at all, so I hope the cause will be the same.
I did a careful workaround for devices which has a legacy level of Camera2 API support - on such we will use Camera1 API.
Please, take a look at 0.82.8_rc2.
If everything is good I'll convert it to the final release 0.82.8.

@sagrawal31
Copy link
Author

I have tested on J5. Unfortunately I was not able to reproduce

Samsung phone box in India has a specific label "Designed for India" so maybe some configuration is different (although, I have heard that it's about SIM slots).

the crash

Actually, by a crash, I meant the same. For us, the recording never starts. Although, preview used to work but as soon as we start the recording, it throws this RuntimeException and after a few minutes (of app being frozen), it crashes (Android OS shows a popup this "Xyz app is not responding").

I did a careful workaround for devices which has a legacy level of Camera2 API support

Did you mean that the SDK is now trying to detect the device which does not properly support/implement Camera2 API and if that condition meets, you use Camera2 API?

If yes, I'm quite afraid @3akat that if we release this, it might break in any of the devices as we have listed above.

Because the release 0.82.8_rc1 seems to be working on the devices where it was crashing earlier.

How can we assure that it won't break on these devices?

@3akat
Copy link
Contributor

3akat commented Mar 18, 2020

Actually, by a crash, I meant the same. For us, the recording never starts. Although, preview used to work but as soon as we start the recording, it throws this RuntimeException and after a few minutes (of app being frozen), it crashes (Android OS shows a popup this "Xyz app is not responding").

That is important details, please describe them exacly next time :) In this case this had no influence but could have in other cases.

Did you mean that the SDK is now trying to detect the device which does not properly support/implement Camera2 API and if that condition meets, you use Camera2 API?

That's right.

How can we assure that it won't break on these devices?

That's a good question. Do you have access to those device or this were remote users?

@sagrawal31
Copy link
Author

That is important details

Actually, I explained this earlier in #26 (comment) & #26 (comment) 😄 never directly used the word "crash" in the beginning but the end result of this issue lead to app crash (after a few minutes).

Do you have access to those device or this were remote users?

We do not have access to all those devices where it was crashing earlier. Some of them are of real end-users.

@3akat
Copy link
Contributor

3akat commented Mar 18, 2020

Actually, I explained this earlier in #26 (comment) & #26 (comment) 😄 never directly used the word "crash" in the beginning but the end result of this issue lead to app crash (after a few minutes).

ah, that means I missed something. For some reason I was focused on RuntimeException: stop failed :)

We do not have access to all those devices where it was crashing earlier. Some of them are of real end-users.

Roger that. I'll try to find out how to make sure that it will be working on the devices you've shared.

@sagrawal31
Copy link
Author

Thank you @3akat

I'll be waiting to hear from you!

@sagrawal31
Copy link
Author

Hi @3akat @Bane-D
Hope you & your families are safe from this pandemic disease.

Any update here?

Our app is crashing for a few students (the end-user) and the count is increasing as soon as we are promoting the app.

@3akat
Copy link
Contributor

3akat commented Mar 29, 2020

Hi @sagrawal31, hope you're doing well too!
Can you please specify the version you use, device name and crash log if possible?
Because in '0.82.8_rc1' I turned off camera2 support, so if you use it then it should be a new issue.

@sagrawal31
Copy link
Author

Hi @3akat, we are using the version 0.82.8_rc1 only. But having a few app unresponsiveness on that as soon as the countdown is stopping. This is not the only behaviour. Some users have faced a different kind of behaviour.

Regarding the logs, I couldn't get anything yet because those are the remote users.

Roger that. I'll try to find out how to make sure that it will be working on the devices you've shared.

But you released 0.82.8_rc2 as well for which you were supposed to debug the issues, right. Because that version 0.82.8_rc2 is failing on my Samsung J6 device so we aren't using it in the app.

@3akat
Copy link
Contributor

3akat commented Mar 30, 2020

Oh I didn't know 0.82.8_rc2 stopped working on J6 again.
But still the issue with 0.82.8_rc1 is different from what we were solving. Let's try to get names of the devices with the issue.

@sagrawal31
Copy link
Author

Oh I didn't know 0.82.8_rc2 stopped working on J6 again.

That's fine, I also didn't know it till yesterday.

Let's try to get names of the devices with the issue.

Yes, @3akat we are trying to prepare a list for you along with the logs. We have Firebase crashlytics installed but for some reason, it is not showing up there.

@3akat
Copy link
Contributor

3akat commented Mar 31, 2020

Hi @sagrawal31, tomorrow I plan to try to integrate crashlitics to see if there is any issues and since I can't reproduce camera issue manually I will write autotest and execute it in cloud. Hope this will help to find the device where I can debug issues you have.

@sagrawal31
Copy link
Author

That would be really really helpful, @3akat

@3akat
Copy link
Contributor

3akat commented Apr 1, 2020

Hi @sagrawal31.
Regarding crash logger - please try with v 0.83.1_cam1. We have internal logger in the SDK and seems like it is conflicting with any other logger system and this is impossible to use both at the same time. So I set the logger in the SDK turned off by default.
You can also try to find some logs from the SDK here
https://ziggeo.com/applications/_your_app_token_/debugger

@sagrawal31
Copy link
Author

Hi @3akat. Thanks for the new release. Is this release v0.83.1_cam1 is extending 0.82.8_rc2?

@sagrawal31
Copy link
Author

Hey, I just checked the debugging page after a very long time and surprised to see that it is logging various errors which might help you figure the issue. Here is a snap:

image

And the biggest thing is that it shows the devices (of real users) on which it is crashing along with my testing Samsung J6 device.

Can you please quickly grab access to this and figure out why we are still having issues with the SDK? Please let me know what you need from me so that you can look into my account's debugger data.

@3akat
Copy link
Contributor

3akat commented Apr 1, 2020

Is this release v0.83.1_cam1 is extending 0.82.8_rc2?

This actually our usual release with some more fixes/improvements, but I have turn Camera2 API off there like in previus time for you.

And thanks for sharing the logs, will analyse :)

@sagrawal31
Copy link
Author

but I have turn Camera2 API off there like in previus time for you.

Thanks a ton for this. I'll try this. But another concern, since we know that your internal logger can track the issue, do you still want me to try that release? Should we use it and release it on our production app?

And thanks for sharing the logs, will analyse :)

I'll be waiting for a more stable fix.

@sagrawal31
Copy link
Author

Any update here @3akat?

@3akat
Copy link
Contributor

3akat commented Apr 5, 2020

Unfortunately no result for now. Currently we have no access to the service with mobile devices which allow to run autotests, so I did manual testing on about 20 more devices with 5 different builds - no issues.
Will try to execute autotest on the next week.

@sagrawal31
Copy link
Author

sagrawal31 commented Apr 6, 2020

Thank you prompt response, again @3akat I appreciate this.

I understand that you are not able to reproduce this on different devices but you have access to these logs which looks pretty straightforward to me. For example: NullPointerException when attempting to call .getParameters() method. Can you please try playing around those lines in your SDK to cover any kind of possible scenarios?

Am I making sense?

@3akat
Copy link
Contributor

3akat commented Apr 6, 2020

Hi @sagrawal31,
First of all in the logs I got from /debugger there are several issues, not only the one you've mentioned.
And you're right: this NullPointerException is pretty clear. I can add check if (camera!=null) do something :)
But this will only prevent a crash, this will not fix the issue, becase the actual reason is that camera is null and this is impossible to do anything with it, so recording will not star anyway.

@3akat
Copy link
Contributor

3akat commented Apr 10, 2020

Hi @sagrawal31,
Just wanted to share a few updates.
We have prepare automated test for several different SDK versions (to cover a wide range of cases), but currently we can't execute them due to issues with the service which provides us real devices.
I'll back to you with updates as soon as I get something.

@sagrawal31
Copy link
Author

Hi, @3akat. Thank you for updating me advance!

Let me know as soon as you have something.

@3akat
Copy link
Contributor

3akat commented Jun 8, 2020

Hi @sagrawal31!
Happy to say we have pushed a new SDK version - 1.0.0. It contains some big changes including migration to AndroidX.
We have been able to execute autotests on more than a hundred devices and found several camera issue - all of them are resolved now.
Please, take look at the new version when you'll have time to updated.
I'm closing this issue, please, open another in case you will face something working not as expected.

@3akat 3akat closed this as completed Jun 8, 2020
@sagrawal31
Copy link
Author

That's really great, @3akat. Thanks for your effort and the update. I'll surely try this very soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants