Git Product home page Git Product logo

cordova-plugin-last-cam's Introduction

Last Cam

Last Cam is a Cordova Plugin that brings to the table what other camera plugins lack: Video Capture capabilities within a custom Camera view.

LastCam

Cordova Plugin Last Cam

GitHub Github GitHub issues GitHub

Releases are being kept up to date when appropriate. However, this plugin is under constant development. As such it is recommended to use master to always have the latest fixes & features.

PR's are greatly appreciated. Maintainer(s) wanted.

Table of Contents

Features

  • Start a camera preview from HTML code.
  • Maintain HTML interactivity.
  • Set a custom position for the camera preview box.
  • Set a custom size for the preview box.

Install

Use any one of the installation methods listed below depending on which framework you use.

To install the master version with latest fixes and features

cordova plugin add https://github.com/bengejd/cordova-plugin-last-cam.git

ionic cordova plugin add https://github.com/bengejd/cordova-plugin-last-cam.git

And Ionic-Native inclusion.

npm install @ionic-native/LastCam

Import LastCam into your constructor.

import {LastCam} from '@ionic-native/last-cam';
...

constructor(private lastCam: LastCam) {
  }
...

iOS Quirks

It is not possible to test in a simulator. You must use a real device for all testing.

config.xml

If you are developing for iOS 10+ you must also add the following to your config.xml

<config-file platform="ios" target="*-Info.plist" parent="NSCameraUsageDescription" overwrite="true">
  <string>Allow the app to use your camera</string>
</config-file>
<config-file platform="ios" target="*-Info.plist" parent="NSPhotoLibraryUsageDescription" overwrite="true">
  <string>Allow the app to save media to your camera roll</string>
</config-file>
<config-file platform="ios" target="*-Info.plist" parent="NSMicrophoneUsageDescription" overwrite="true">
  <string>Allow access to your microphone to record video with audio</string>
</config-file>

app.scss

Be sure to include the following in your app.scss, or else the camera-preview will not display.

html, body, .ion-app, .ion-content {
  background-color: transparent !important;
}

Note

LastCam will build and link the underlying framework on it's own, but it will display a few errors within your XCode project on run-time. This is purely a cosmetic error, and will not affect the functioning of the plugin. I am working on a solution for this in the meantime, but do not worry. The plugin will compile and run without issue.

Usage

startCamera(options, [successCallback, errorCallback])

Starts the camera preview instance.

Options: All options stated are optional and will default to values here

  • x - Defaults to 0
  • y - Defaults to 0
  • width - Defaults to window.screen.width
  • height - Defaults to window.screen.height
  • camera - Defaults to back camera
let options = {
  x: 0,
  y: 0,
  width: window.screen.width,
  height: window.screen.height,
  camera: ".Back",
};

CameraPreview.startCamera(options)
.then(() => { })
.catch(error => console.log(error));

stopCamera([successCallback, errorCallback])

Stops the camera preview instance.

CameraPreview.stopCamera();

switchCamera([successCallback, errorCallback])

Switches between the front and back camera, if they are available.

Returns a string containing the camera direction ('front' or 'back')

CameraPreview.switchCamera()
.then(direction => {
    console.log('New camera direction: ', direction)
})
.catch(err => { 
    console.log(err);
});

switchFlash([successCallback, errorCallback])

Switches the flash mode between 0 (off), 1 (on) and 2(auto).

Returns an int containing the flash mode: 0, 1, or 2

CameraPreview.switchFlash()
.then(mode => {
    console.log('New flash mode: ', mode)
})
.catch(err => { 
    console.log(err);
});

takePicture([successCallback, errorCallback])

Takes a picture

CameraPreview.takePicture().then(base64PictureData) {
  /*
    base64PictureData is base64 encoded jpeg image. Use this data to store to a file or upload.
    Its up to the you to figure out the best way to save it to disk or whatever for your application.
  */
};
Here is and example of how you use the `base64PictureData`
  imageSrcData = 'data:image/jpeg;base64,' + base64PictureData;

Now it can be put into a regular <img src="imageSrcData"> tag.

If you run into issues with the imageSrcData being caught by Angular or Ionic as an unsafeXss, you can do the following the fix the error:

In your component.ts file

import {DomSanitizer} from '@angular/platform-browser';
...

constructor(private DomSanitizer: DomSanitizer){
...
}

In your component.html file

<img [src]="DomSanitizer.bypassSecurityTrustResourceUrl(imageSrcData)">

startVideoCapture([successCallback, errorCallback])

Starts the video recording session. You will see a brief flicker. This is not a bug.

CameraPreview.startVideoCapture().then(() => {
    console.log('Video Capture started');
})
.catch(err => { 
    console.log(err);
});

stopVideoCapture([successCallback, errorCallback])

Stops the video recording session. You will see a brief flicker. This is not a bug.

Example fileURI that is returned: /var/mobile/Containers/Data/Application/.../filename.mp4

CameraPreview.startVideoCapture().then(fileURI => {
	  /*
        fileURI is a local path to the video recording on the user's device.
        Its up to the you to figure out the best way display and upload the video source.
      */
})
.catch(err => { 
    console.log(err);
});

recordingTimer([successCallback, errorCallback])

This returns the current recording time, while actively recording.

CameraPreview.recordingTimer().then(time => {
	console.log('Recording length: ', time);
})
.catch(err => { 
    console.log(err);
});

Alternative Plugins

cordova-plugin-camera-preview - Custom Preview, but does not allow video capture & has high processing usage.

cordova-background-video - Custom preview, only allows video capture.

cordova-plugin-camera - Native camera interface. Allows for Video & Photo capture. Limited customization.

cordova-plugin-video-capture-plus - No longer maintained. Limited customizations.

cordova-plugin-media-capture - Last time I checked, this had some processing issues & bugs that had not been addressed.

License

MIT License

Copyright (c) 2018 Jordan Benge

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Credits

LastCam was Created by Jordan Benge @bengejd

CameraManager, which LastCam utilizes was created by imaginary-cloud @imaginary-cloud

cordova-plugin-last-cam's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

cordova-plugin-last-cam's Issues

Camera preview instantiation issue

Short version: I see no camera preview.

Issue, here is the key word. I say this because I am not receiving any errors from neither Xcode nor web inspector.

Let me explain a bit what I have encountered while attempting to load your plugin into a blank ionic 4 project.

Initially, I had errors following the install instructions from the official Ionic documentation.

The repositories failed to download from the provided links.

After installing the plugin using the git links you provide in the documentation, I was able to load it into the project.

Next, I attempted a build, it failed. This was purely an issue with my version of Swift being outdated.

As a note for anyone reading this at a later date, be sure to update your Xcode installation to at least 10.1. This will update your Swift installation to the minimum version required, v4.2. If possible, overwrite your old version of Xcode so the system version will default to Swift v4.2. If not, you will need to manually switch versions.

Once I did this, I was able to compile a build without error.

Actually, let me back up... There are a few deprecations in the LastCam.swift file. I will attempt a pull request once I am actually able to get the plugin running in the project.

I went a step further and compiled the CameraManager v4.3 into a framework using Carthage and replaced the version included in the libs source of this project. But, the problem persists.

Once I load the project. The camera instantiates with a success result from the startCamera function. Actually, all of the methods function properly. However, I see no camera preview.

Any suggestions?

Here is my Ionic info

cli packages: (/usr/local/opt/nvm/versions/node/v6.9.2/lib/node_modules)

    @ionic/cli-utils  : 1.19.2
    ionic (Ionic CLI) : 3.20.0

global packages:

    cordova (Cordova CLI) : 8.1.2 ([email protected]) 

local packages:

    @ionic/app-scripts : 3.2.1
    Cordova Platforms  : ios 4.5.5
    Ionic Framework    : ionic-angular 3.9.3

System:

    ios-deploy : 2.0.0 
    ios-sim    : 6.1.2 
    Node       : v9.11.2
    npm        : 5.6.0 
    OS         : macOS High Sierra
    Xcode      : Xcode 10.1 Build version 10B61 

Unsupported Archetypes on Apple store upload.

screen shot 2018-11-05 at 10 14 03 am

When uploading to the app store, I had this error, due to how CameraManager has unsupported archetypes built in the framework (simulator archetypes x86_64, i386). The current workaround is to add a custom build phase script that strips frameworks of the unsupported archetypes.

Go to Xcode > build phases > Editor menu bar > Add build phase > Add run script build phase > and copy the below script into the .bin/sh that is below your "Embedded binaries" in Xcode.

# This removes the unsupported archetypes from frameworks on the build phase.
echo "Target architectures: $ARCHS"

APP_PATH="${TARGET_BUILD_DIR}/${WRAPPER_NAME}"

find "$APP_PATH" -name '*.framework' -type d | while read -r FRAMEWORK
do
FRAMEWORK_EXECUTABLE_NAME=$(defaults read "$FRAMEWORK/Info.plist" CFBundleExecutable)
FRAMEWORK_EXECUTABLE_PATH="$FRAMEWORK/$FRAMEWORK_EXECUTABLE_NAME"
echo "Executable is $FRAMEWORK_EXECUTABLE_PATH"
echo $(lipo -info "$FRAMEWORK_EXECUTABLE_PATH")

FRAMEWORK_TMP_PATH="$FRAMEWORK_EXECUTABLE_PATH-tmp"

# remove simulator's archs if location is not simulator's directory
case "${TARGET_BUILD_DIR}" in
*"iphonesimulator")
    echo "No need to remove archs"
    ;;
*)
    if $(lipo "$FRAMEWORK_EXECUTABLE_PATH" -verify_arch "i386") ; then
    lipo -output "$FRAMEWORK_TMP_PATH" -remove "i386" "$FRAMEWORK_EXECUTABLE_PATH"
    echo "i386 architecture removed"
    rm "$FRAMEWORK_EXECUTABLE_PATH"
    mv "$FRAMEWORK_TMP_PATH" "$FRAMEWORK_EXECUTABLE_PATH"
    fi
    if $(lipo "$FRAMEWORK_EXECUTABLE_PATH" -verify_arch "x86_64") ; then
    lipo -output "$FRAMEWORK_TMP_PATH" -remove "x86_64" "$FRAMEWORK_EXECUTABLE_PATH"
    echo "x86_64 architecture removed"
    rm "$FRAMEWORK_EXECUTABLE_PATH"
    mv "$FRAMEWORK_TMP_PATH" "$FRAMEWORK_EXECUTABLE_PATH"
    fi
    ;;
esac

echo "Completed for executable $FRAMEWORK_EXECUTABLE_PATH"
echo $(lipo -info "$FRAMEWORK_EXECUTABLE_PATH")

done

A temporary workaround, until I can come up with something more concrete.

Analysing frames of preview

How can we process the frames of the preview using this plugin? Is the most desired functionality. Could somebody please add this functionality?

Class not found

Good Morning,
I started a plugin test with an Ionic blank and am encountering this error: ERROR Error: Uncaught (in promise): Class not found.

screen shot 2018-10-22 at 08 13 09

This is the code on my screen:

import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import { LastCam } from '@ionic-native/last-cam';

@Component({
  selector: 'page-home',
  templateUrl: 'home.html',
  providers: [ LastCam ]
})
export class HomePage {

  cameraOpts: any = {
    x: 0,
    y: 0,
    width: window.screen.width,
    height: window.screen.height,
    camera: 'rear'
  };

  constructor(
    public navCtrl: NavController,
    private lastCam: LastCam
  ) {
  }

  ionViewDidEnter() {
    // start camera
    this.lastCam.startCamera(this.cameraOpts);
  }

  teste() {
    this.lastCam.startVideoCapture().then((fileUri: any) => {
      console.log('Video Capture started', fileUri);
    })
    .catch(err => { 
      console.log(err);
    });
  }
}

My project environment:
ionic: 3.19.0
ionic-angular: 3.9.2
cordova 6.5.0
node 8.12.0

Device: Samsung galaxy s9+

Anyway, good initiative, since we have many problems with media-capture and we do not have many options of plugins to use.

<unknown>:0: error: using bridging headers with module interfaces is unsupported Command CompileSwiftSources failed with a nonzero exit code

After I built the iOS Version of the Ionic v4 App, I get the following error while building to run in Xcode:
<unknown>:0: error: using bridging headers with module interfaces is unsupported Command CompileSwiftSources failed with a nonzero exit code
Ionic:

Ionic CLI : 5.4.5 (/usr/local/lib/node_modules/ionic)
Ionic Framework : @ionic/angular 4.11.10
@angular-devkit/build-angular : 0.801.3
@angular-devkit/schematics : 8.1.3
@angular/cli : 8.1.3
@ionic/angular-toolkit : 2.3.0

Cordova:

Cordova CLI : not installed
Cordova Platforms : not available
Cordova Plugins : not available

Utility:

cordova-res : not installed
native-run : 1.0.0

System:

ios-sim : 8.0.2
NodeJS : v12.14.0 (/usr/local/bin/node)
npm : 6.13.4
OS : macOS Catalina
Xcode : Xcode 11.6 Build version 11E708

Module complied with swift 5.2 cannot be imported with swift 5.5.2

I am stuck for a long time now, need help. After installing the plugin my build fails with error /Users/xxx/Projects/xxx/xxx/src-cordova/platforms/ios/xxx App/Plugins/cordova-plugin-last-cam/LastCam.swift:7:8: Module compiled with Swift 5.2 cannot be imported by the Swift 5.5.2 compiler: /Users/xxx/Projects/xxx/xxx-app/src-cordova/platforms/ios/xxx App/Plugins/cordova-plugin-last-cam/CameraManager.framework/Modules/CameraManager.swiftmodule/arm64.swiftmodule

Can you help me please, is this issue with my Xcode version?

I am using Xcode cli 13.2.1

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.