triniwiz / nativescript-videorecorder

:video_camera: NativeScript plugin for Video Recording . :video_camera:
Apache License 2.0
43 stars 29 forks source link

AdvancedVideoView crashes App on start #78

Open FariJan opened 4 years ago

FariJan commented 4 years ago

On start my app crashes with following Error-Log:

Calling js method onCreateView failed
Error: java.lang.IllegalStateException: CameraX is not initialized properly. Either CameraX.initialize() needs to have been called or the CameraXConfig.Provider interface must be implemented by your Application class.

StackTrace:
AdvancedVideoView.createNativeView(file:` node_modules\nativescript-videorecorder\advanced\advanced-video-view.android.js:47:15)
    at ViewBase._setupUI(file: node_modules\@nativescript\core\ui\core\view-base\view-base.js:511:30)
    at (file: node_modules\@nativescript\core\ui\core\view-base\view-base.js:553:18)
    at LayoutBaseCommon.eachChildView(file: node_modules\@nativescript\core\ui\layouts\layout-base-common.js:125:25)
    at ViewCommon.eachChild(file: node_modules\@nativescript\core\ui\core\view\view-common.js:925:13)
    at ViewBase._setupUI(file: node_modules\@nativescript\core\ui\core\view-base\view-base.js:552:13)
    at (file: node_modules\@nativescript\core\ui\core\view-base\view-base.js:553:18)
    at ContentView.eachChildView(file: node_modules\@nativescript\core\ui\content-view\content-view.js:70:12)
    at PageBase.eachChildView(file: node_modules\@nativescript\core\ui\page\page-common.js:126:39)
    at ViewCommon.eachChild(file: node_modules\@nativescript\core\ui\core\view\view-common.js:925:13)
    at ViewBase._setupUI(file: node_modules\@nativescript\core\ui\core\view-base\view-base.js:552:13)
    at ViewBase._addViewCore(file: node_modules\@nativescript\core\ui\core\view-base\view-base.js:448:17)
    at ViewBase._addView(file: node_modules\@nativescript\core\ui\core\view-base\view-base.js:437:13)
    at FragmentCallbacksImplementation.onCreateView(file: node_modules\@nativescript\core\ui\frame\frame.android.js:700:18)
    at FragmentClass.onCreateView(file: node_modules\@nativescript\core\ui\frame\fragment.android.js:29:37)
    at com.tns.Runtime.callJSMethodNative(Native Method)
    at com.tns.Runtime.dispatchCallJSMethodNative(Runtime.java:1286)
    at com.tns.Runtime.callJSMethodImpl(Runtime.java:1173)
    at com.tns.Runtime.callJSMethod(Runtime.java:1160)
    at com.tns.Runtime.callJSMethod(Runtime.java:1138)
    at com.tns.Runtime.callJSMethod(Runtime.java:1134)
    at com.tns.FragmentClass.onCreateView(FragmentClass.java:53)
    at androidx.fragment.app.Fragment.performCreateView(Fragment.java:2439)
    at androidx.fragment.app.FragmentManagerImpl.moveToState(FragmentManager.java:1460)
    at androidx.fragment.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1784)
    at androidx.fragment.app.FragmentManagerImpl.moveToState(FragmentManager.java:1852)
    at androidx.fragment.app.BackStackRecord.executeOps(BackStackRecord.java:802)
    at androidx.fragment.app.FragmentManagerImpl.executeOps(FragmentManager.java:2625)
    at androidx.fragment.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2411)
    at androidx.fragment.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManager.java:2366)
    at androidx.fragment.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:2273)
    at androidx.fragment.app.FragmentManagerImpl$1.run(FragmentManager.java:733)
    at android.os.Handler.handleCallback(Handler.java:883)
    at android.os.Handler.dispatchMessage(Handler.java:100)
    at android.os.Looper.loop(Looper.java:237)
    at android.app.ActivityThread.main(ActivityThread.java:7811)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1076)
Caused by: java.lang.IllegalStateException: CameraX is not initialized properly. Either CameraX.initialize() needs to have been called or the CameraXConfig.Provider interface must be implemented by your Application class.
    at androidx.camera.core.CameraX.getOrCreateInstance(CameraX.java:797)
    at androidx.camera.lifecycle.ProcessCameraProvider.getInstance(ProcessCameraProvider.java:98)
    at co.fitcom.fancycamera.FancyCamera.init(FancyCamera.kt:214)
    at co.fitcom.fancycamera.FancyCamera.<init>(FancyCamera.kt:159)
    System.err:     ... 24 more

Found this on Stackoverflow https://stackoverflow.com/a/59376041/10947127 but have no idea how to use this or if it could help.

Which platform(s) does my issue occur on?

Version numbers that my issue occurs with:

how to recreate the issue in as much detail as possible.

Is there any code involved?

main.ts

import Vue from 'nativescript-vue';

Vue.registerElement('AdvancedVideoView', () => require('nativescript-videorecorder/advanced').AdvancedVideoView);

new Vue({

  render: h => h('frame', [h(App)])
}).$start();

App.vue

<template>
    <Page>
        <StackLayout orientation="horizontal">
            <AdvancedVideoView
                ref="cameraView"
                height="700"
                width="300"
                quality="MAX_1080p"
                cameraPosition="back"
                fill="true"/>
        </StackLayout>
    </Page>
</template>

<script lang="ts">
    import Vue from "nativescript-vue";
    import { Component } from "vue-property-decorator";
    @Component({})
    export default class App extends Vue {
    }
</script>

<style lang="scss">
</style>
ElieSol commented 4 years ago

Hello FariJan did you find a solution to this ? Have the same issue here (working with Nativescript-Vue + Typescript) and didn't manage to fix it with the stackoverflow solutions ^^

FariJan commented 4 years ago

I used the fork Videorecorder X https://market.nativescript.org/plugins/nativescript-videorecorder-x No problem with this

ElieSol commented 4 years ago

Great I will try this, thank you @FariJan :)

ElieSol commented 4 years ago

Hi again @FariJan , may I ask if you are able (and how) using Nativescript Vue+ Typescript to call the method .startRecording() in the App script ?

FariJan commented 4 years ago

@ElieSol yes

...
<AdvancedVideoView
                ref="cameraView" ...

...

<script lang="ts">
    //...//
    import NativeViewElement from "@/interfaces/NativeViewElement";
    import {AdvancedVideoView} from "nativescript-videorecorder-x/advanced";
    //...//
@Component
    export default class RecordVideo extends Vue {
        videoRecorder:AdvancedVideoView;
        onLoaded(){
           this.videoRecorder = (<NativeViewElement>this.$refs['cameraView']).nativeView as AdvancedVideoView;
       //...//
           this.videoRecorder.startRecording();
ElieSol commented 4 years ago

@FariJan Thank you very much !! This helps a lot :)