Xamarin error when recording audio: stop failed android.media.MediaRecorder.stop

Uttam 6 Reputation points
2021-07-21T16:13:54.237+00:00

I am getting this error when I try to record audio on my app. It was working fine but when I switched the target API to 29 as required by google to upload the app on the store I started getting this error. It looks like I am getting error when I try to access external storage. Is there any way to access internal storage? I dont see anything about this.

Here is the line of code:
116797-image.png

Here is the Error I am getting:

{Java.Lang.RuntimeException: stop failed.
at Java.Interop.JniEnvironment+InstanceMethods.CallVoidMethod (Java.Interop.JniObjectReference instance, Java.Interop.JniMethodInfo method, Java.Interop.JniArgumentValue* args) [0x0006e] in <f1f8dcdb8c91400fb3213a928a387983>:0
at Java.Interop.JniPeerMembers+JniInstanceMethods.InvokeVirtualVoidMethod (System.String encodedMember, Java.Interop.IJavaPeerable self, Java.Interop.JniArgumentValue* parameters) [0x0002a] in <f1f8dcdb8c91400fb3213a928a387983>:0
at Android.Media.MediaRecorder.Stop () [0x00000] in /Users/builder/azdo/_work/278/s/xamarin-android/src/Mono.Android/obj/Release/monoandroid10/android-28/mcw/Android.Media.MediaRecorder.cs:1934
at Droid.Services.AndroidSoundProvider.StopAudioRecording (System.Int32 userid) [0x000e2] in <bd60d41757dc4dff800b975fe52399da>:0
at Services.SoundService.StopAudioRecording (System.Int32 userid) [0x0002b] in \Services\SoundService.cs:25
at Pages.AudioRecord.BtnStopClicked (System.Object sender, System.EventArgs e) [0x00200] in \Pages\AudioRecord.xaml.cs:105
--- End of managed Java.Lang.RuntimeException stack trace ---
java.lang.RuntimeException: stop failed.
at android.media.MediaRecorder.stop(Native Method)
at mono.java.lang.RunnableImplementor.n_run(Native Method)
at mono.java.lang.RunnableImplementor.run(RunnableImplementor.java:30)
at android.os.Handler.handleCallback(Handler.java:883)
at android.os.Handler.dispatchMessage(Handler.java:100)
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)

Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,347 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Leon Lu (Shanghai Wicresoft Co,.Ltd.) 75,351 Reputation points Microsoft Vendor
    2021-07-22T01:05:01.147+00:00

    Hello,​

    Welcome to our Microsoft Q&A platform!

    Is there any way to access internal storage? I dont see anything about this.

    Yes, you can use following code to create internal storage file folder.

       var dir=new Java.IO.File(Android.App.Application.Context.GetExternalFilesDir("").AbsolutePath,"Audio");  
                   if (!dir.Exists())  
                   {  
                       dir.Mkdirs();  
                   }  
    

    `

    116837-image.png

    Best Regards,

    Leon Lu


    If the response is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.