nstudio / nativescript-camera-plus

MIT License
79 stars 50 forks source link

[EXCEPTION] .record() throwing exception "java.io.IOException: prepare failed." #135

Closed sido420 closed 3 years ago

sido420 commented 4 years ago

.record() is throwing exception below on Android

JS: NativeScript-CameraPlus --- [true]
System.err: java.io.IOException: prepare failed.
System.err:     at android.media.MediaRecorder._prepare(Native Method)
System.err:     at android.media.MediaRecorder.prepare(MediaRecorder.java:1028)
System.err:     at co.fitcom.fancycamera.Camera2.setUpMediaRecorder(Camera2.java:701)
System.err:     at co.fitcom.fancycamera.Camera2.startRecording(Camera2.java:931)
System.err:     at co.fitcom.fancycamera.FancyCamera.startRecording(FancyCamera.java:323)
System.err:     at com.tns.Runtime.callJSMethodNative(Native Method)
System.err:     at com.tns.Runtime.dispatchCallJSMethodNative(Runtime.java:1286)
System.err:     at com.tns.Runtime.callJSMethodImpl(Runtime.java:1173)
System.err:     at com.tns.Runtime.callJSMethod(Runtime.java:1160)
System.err:     at com.tns.Runtime.callJSMethod(Runtime.java:1138)
System.err:     at com.tns.Runtime.callJSMethod(Runtime.java:1134)
System.err:     at com.tns.gen.java.lang.Object_vendor_30628_32_ClickListenerImpl.onClick(Object_vendor_30628_32_ClickListenerImpl.java:18)
System.err:     at android.view.View.performClick(View.java:6312)
System.err:     at android.view.View$PerformClick.run(View.java:24802)
System.err:     at android.os.Handler.handleCallback(Handler.java:790)
System.err:     at android.os.Handler.dispatchMessage(Handler.java:99)
System.err:     at android.os.Looper.loop(Looper.java:169)
System.err:     at android.app.ActivityThread.main(ActivityThread.java:6521)
System.err:     at java.lang.reflect.Method.invoke(Native Method)
System.err:     at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
System.err:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)

I have tried using different options but still the same issue. .takePicture() seems to work fine.

Dependencies and Versions:

        "tns-android": {
            "version": "6.5.0"
        }
...

        "@nativescript/core": "6.5.0",
        "@nativescript/theme": "^2.3.3",
        "@nstudio/nativescript-camera-plus": "^3.0.7",
        "@nstudio/nativescript-loading-indicator": "^3.0.4",
        "dotenv": "^8.2.0",
        "localforage": "^1.9.0",
        "localforage-memoryStorageDriver": "^0.9.2",
        "nativescript-accelerometer": "3.0.0",
        "nativescript-background-http": "4.2.1",
        "nativescript-contacts": "^1.6.2",
        "nativescript-exoplayer": "^4.0.2",
        "nativescript-feedback": "^1.5.0",
        "nativescript-geolocation": "5.1.0",
        "nativescript-https": "^2.1.0",
        "nativescript-image": "3.0.1",
        "nativescript-imagepicker": "7.1.0",
        "nativescript-intl": "3.0.0",
        "nativescript-iqkeyboardmanager": "1.5.1",
        "nativescript-oauth2": "^2.4.2",
        "nativescript-perms": "^2.0.11",
        "nativescript-secure-storage": "^2.6.1",
        "nativescript-social-share": "1.6.0",
        "nativescript-theme-core": "1.0.6",
        "nativescript-toast": "^2.0.0",
        "nativescript-ui-autocomplete": "6.0.1",
        "nativescript-ui-calendar": "6.1.0",
        "nativescript-ui-chart": "7.1.1",
        "nativescript-ui-dataform": "6.0.0",
        "nativescript-ui-gauge": "6.0.0",
        "nativescript-ui-listview": "8.0.1",
        "nativescript-ui-sidedrawer": "8.0.0",
        "nativescript-urlhandler": "^1.3.0",
        "nativescript-vibrate": "^3.1.0",
        "nativescript-vue": "2.5.0",
        "svelte-native": "0.8.1",
        "tns-core-modules": "6.5.0"
bradmartin commented 4 years ago

Is it possible the permission to record hasn't been granted?

sido420 commented 4 years ago

Nope, that does not seem to be the issue.

  function recordVideo() {
    console.log("Recording Video");
    console.log(`Has camera permission? ${camera.hasCameraPermission()}`);
    console.log(`Has storage permission? ${camera.hasStoragePermissions()}`);
    camera.record({}); 
  }

which ends up printing:

JS: Recording Video
JS: Has camera permission? true
JS: Has storage permission? true
JS: NativeScript-CameraPlus --- [true]
System.err: java.io.IOException: prepare failed.
System.err:     at android.media.MediaRecorder._prepare(Native Method)
System.err:     at android.media.MediaRecorder.prepare(MediaRecorder.java:1028)
System.err:     at co.fitcom.fancycamera.Camera2.setUpMediaRecorder(Camera2.java:701)
System.err:     at co.fitcom.fancycamera.Camera2.startRecording(Camera2.java:931)
System.err:     at co.fitcom.fancycamera.FancyCamera.startRecording(FancyCamera.java:323)
System.err:     at com.tns.Runtime.callJSMethodNative(Native Method)
System.err:     at com.tns.Runtime.dispatchCallJSMethodNative(Runtime.java:1286)
System.err:     at com.tns.Runtime.callJSMethodImpl(Runtime.java:1173)
System.err:     at com.tns.Runtime.callJSMethod(Runtime.java:1160)
System.err:     at com.tns.Runtime.callJSMethod(Runtime.java:1138)
System.err:     at com.tns.Runtime.callJSMethod(Runtime.java:1134)
System.err:     at com.tns.gen.java.lang.Object_vendor_30628_32_ClickListenerImpl.onClick(Object_vendor_30628_32_ClickListenerImpl.java:18)
System.err:     at android.view.View.performClick(View.java:6312)
System.err:     at android.view.View$PerformClick.run(View.java:24802)
System.err:     at android.os.Handler.handleCallback(Handler.java:790)
System.err:     at android.os.Handler.dispatchMessage(Handler.java:99)
System.err:     at android.os.Looper.loop(Looper.java:169)
System.err:     at android.app.ActivityThread.main(ActivityThread.java:6521)
System.err:     at java.lang.reflect.Method.invoke(Native Method)
System.err:     at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
System.err:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
bradmartin commented 4 years ago

Looks like it might be one of the settings on the MediaRecorder that needs to be adjusted or set prior to calling prepare. https://stackoverflow.com/questions/14640734/mediarecorder-ioexception-prepare-failed

sido420 commented 4 years ago

I did add the two permissions in manifest file, cleaned android project, and reran but still hitting the same issue.

Did I do it wrong?

triniwiz commented 3 years ago

Fixed: https://github.com/nstudio/nativescript-camera-plus/commit/b24997c918df8ceafb73443708a58708be46d5ed feel free to reopen :- update to 3.1.x