Android Question androidvideocapture: setaudiosource failed error

phukol

Active Member
Licensed User
Longtime User
Just want to ask why i am receiving this error when i try to record video
B4X:
Error occurred on line: 0 (Video_Upload)
java.lang.RuntimeException: setAudioSource failed.
    at android.media.MediaRecorder._setAudioSource(Native Method)
    at android.media.MediaRecorder.setAudioSource(MediaRecorder.java:688)
    at videowrapper.videoWrapper.prepareMediaRecorder(videoWrapper.java:398)
    at videowrapper.videoWrapper.setStartStopRecording(videoWrapper.java:282)
    at ed.wais.video_upload._b1_click(video_upload.java:549)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:710)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:339)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:249)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:139)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:170)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:166)
    at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:80)
    at android.view.View.performClick(View.java:6213)
    at android.widget.TextView.performClick(TextView.java:11074)
    at android.view.View$PerformClick.run(View.java:23645)
    at android.os.Handler.handleCallback(Handler.java:751)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:154)
    at android.app.ActivityThread.main(ActivityThread.java:6692)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1468)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1358)
null: 206

I already have set permission in my manifest code:

AddManifestText(
<uses-sdk android:minSdkVersion="17" android:targetSdkVersion="25"/>
<supports-screens android:largeScreens="true"
android:normalScreens="true"
android:smallScreens="true"
android:anyDensity="true"/>)

AddManifestText(<uses-feature android:name="android.hardware.telephony" android:required="false" />)
AddManifestText(<uses-feature android:name="android.hardware.camera" android:required="false" />)
AddManifestText(<uses-feature android:name="android.hardware.camera.autofocus" android:required="false" />)
AddManifestText(<uses-feature android:name="android.hardware.camera.flash" android:required="false" />)

AddPermission("android.permission.WAKE_LOCK")
AddPermission("android.permission.DEVICE_POWER")
AddPermission("android.permission.READ_PHONE_STATE")
AddPermission("android.permission.VIBRATE")
AddPermission("android.permission.CAMERA")
AddPermission("android.permission.FLASHLIGHT")
AddPermission("android.hardware.camera")
AddPermission("android.permission.RECORD_AUDIO")
AddPermission("android.permission.WRITE_EXTERNAL_STORAGE")
 

DonManfred

Expert
Licensed User
Longtime User
Upvote 0

phukol

Active Member
Licensed User
Longtime User
You need to use runtimepermission with this sdk level.
At least two of the permissions are dangerous permission and need a permissionrequest.
External storage and record audio

See RuntimePermissions tutorial.

thanks DonManFred,

For anyone who has this issue, what i did is to first request rp.CheckAndRequest(rp.PERMISSION_CAMERA) inside my button for camera action. then inside the permissions sub i asked for other needed permissions like this one:

B4X:
Sub Activity_PermissionResult (Permission As String, Result As Boolean)
    If Permission = rp.PERMISSION_RECORD_AUDIO Then
        rp.CheckAndRequest(rp.PERMISSION_CAMERA)
    End If
   
    If Permission = rp.PERMISSION_CAMERA Then
        rp.CheckAndRequest(rp.PERMISSION_WRITE_EXTERNAL_STORAGE)
    End If
   
    If Permission = rp.PERMISSION_WRITE_EXTERNAL_STORAGE Then
 
            'start camera or video
    End If
End Sub
 
Upvote 0
Top