简体   繁体   中英

Why does Ionic not recognize the functions I added to a cordova plugin?

What am I trying to do?

I am building a camera app with ionic and the cordova-plugin-camera-preview ( https://github.com/cordova-plugin-camera-preview/cordova-plugin-camera-preview ) and need to record video. I have the preview setup in the app correctly with a simple record button on top 没有录制功能的应用程序的屏幕截图 I want to add video recording function to the plugin and being able to call CameraPreview.startRecording and CameraPreview.stopRecording .

What I have added to the plugin?

Added video recording functionality to the plugin for the android platform and added the exec functions in CameraPreview.js and the function signatures in CameraPreview.d.ts .

What is going wrong?

In my home.page.ts from my project, I am trying to call this.cameraPreview.startRecording() and this.cameraPreview.stopRecording() but when I run ionic cordova run android I get the following error:

ERROR in src/app/home/home.page.ts:90:32 - error TS2339: Property 'startRecording' does not exist on type 'CameraPreview'.

90             this.cameraPreview.startRecording();
                                  ~~~~~~~~~~~~~~
src/app/home/home.page.ts:92:32 - errorgn TS2339: Property 'stopRecording' does not exist on type 'CameraPreview'.

92             this.cameraPreview.stopRecording();
                                  ~~~~~~~~~~~~~

[ERROR] An error occurred while running subprocess ng.

        ng run app:ionic-cordova-build --platform=android exited with exit code 1.

What have I tried so far?

  • removing and adding the android platform to recompile plugin. The plugin is getting re-compiled (checked this by adding a Log.d() function call and running adb logcat to find it). So the code is being added.
  • running npm install after editing plugin
  • making the changes to the plugin in the node_modules folder within my ionic project
  • adding the plugin directly by copying the plugin folder to a different directory and then adding the plugin via the copied plugin
  • a variety of other things I can't remember

Help please? :sweat_smile:

Let me know if you want to see any of the files I mentioned.

Summary

The problem has to do with editing the plugin I linked in the question and then using the functions I added to the plugin. I have added video recording functionality to the plugin: a startRecording function and stopRecording function (and other stuff for configuring the camera for video recording). My ionic app works fine with the camera-preview (runs on android device) but when I try and call the functions I added (startRecording and stopRecording) I get the error listed above.

You haven't made it clear from the question if you understand that you need to use Ionic Native plugin as well with this cordova plugin.

From the way that you're talking it sounds like you have copied individual bits of code into your project.

You need to use this with it:

The general setup instructions for Ionic Native are here:

But even if you have done, looking at the plugin you linked out to - there are no recording options with it.

It's the camera preview only. Have you mixed up your plugins?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM