Socket
Socket
Sign inDemoInstall

nativescript-videorecorder

Package Overview
Dependencies
15
Maintainers
3
Versions
36
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    nativescript-videorecorder

NativeScript Video Recording plugin


Version published
Maintainers
3
Install size
373 kB
Created

Readme

Source

npm npm

NativeScript VideoRecorder

Install

tns plugin add nativescript-videorecorder

QuickStart

JavaScript
var vr = require('nativescript-videorecorder');

var options = {
    saveToGallery: true,
    duration: 30,
    format: 'mp4',
    size: 10,
    hd: true,
    explanation: 'Why do i need this permission'
}

var videorecorder = new vr.VideoRecorder(options);

videorecorder.record().then((data)=>{
  console.log(data.file)
}).catch((err)=>{
  console.log(err)
})
TypeScript
import { VideoRecorder, Options as VideoRecorderOptions } from 'nativescript-videorecorder';

const options: VideoRecorderOptions = {
    hd: true
    saveToGallery: true
}
const videorecorder = new VideoRecorder(options)

videorecorder.record().then((data) => {
    console.log(data.file)
}).catch((err) => {
    console.log(err)
})

VideoRecorder

Options

Option object can be given to the constructor of VideoRecorder or as VideoRecorder::record parameter (as an override).

  • hd?: boolean - If true, highest quality of device, if false MMS quality (default: false)
  • saveToGallery?: boolean - Enable to save the video in the device Gallery, otherwise it will be store within the sandbox of the app (default: false)
  • duration?: number - Limit the duration of the video, 0 for unlimited (default: 0)
  • position?: 'front' | 'back' | 'none' - Force which device camera should be used, 'none' for no preferences (default: none)

Additional parameters for Android:

  • size?: number - Limit the size of the video, 0 for unlimited (default: 0)
  • explanation?: string - Why permissions should be accepted, optional on api > 23

Additional parameters for iOS:

  • format?: 'default' | 'mp4' - allows videos to be played on android devices (default: 'default') recommended for cross platform apps

VideoRecorder attributes:

  • options: Options Option object (see above section), can be set from the constructor

VideoRecorder methods:

  • record(options?: Options): Promise<{ file?: string } > Return a Promise with an object containing the filepath as file key. It may not be there if the video has been saved to the gallery. An optional options parameter can be given to override instance options, this is deprecated.
  • requestPermissions(): Promise Return a Promise, resolved if permissions are OK (ask for permissions if not), rejected if user didn't have accepted the permissions. This method is implicitely called by record()
  • isAvailable(): boolean Check if device has a camera and is compatible with what has been set in options

Promises above can be rejected with:

  • { event: 'denied'} - Permissions have not been accepted
  • { event: 'cancelled'} - Video capture have been canceled
  • { event: 'failed'} - Generic error

AdvancedVideoView

AdvancedVideoView does not open the device camera application, but rather allows you to embed the camera view in your app. You can then add buttons over it to start/stop recording. It allows for a deeper level of UI customization.

Requires API 21+ on Android 🤖

<Page xmlns="http://schemas.nativescript.org/tns.xsd" xmlns:recorder="nativescript-videorecorder/advanced">
<recorder:AdvancedVideoView quality="highest" cameraPosition="front" id="camera"/>
const advancedView = page.getViewById("camera");
advancedView.startRecording();

Api

MethodDefaultTypeDescription
start()voidStarts the camera preview
stop()voidStop the camera preview
startRecording()voidStart recording camera preview.
stopRecording()voidStop recording camera preview.
toggleCamera()voidToggles between front or the back camera.
toggleTorch()voidToggles the torch (iOS only for now)
durationintGet the current recording video duration.
cameraPositionBACKvoidGets or Sets camera position
outputOrientationPORTRAITvoidGets or Sets output video orientation
isTorchAvailablebooleanReadOnly: is the torch supported for this camera
torchfalsebooleanEnable/Disable torch (iOS only for now)
qualityMAX_480PvoidGets or sets Video Quality
outputOrientation

Be careful to not change orientation while recording, it's not supported.

Possible values : portrait, portraitUpsideDown, landscapeLeft, landscapeRight, you can also use the Orientation enum.

This property let you manage the orientation of the output file correctly, it means you can trust your gravity sensors to detect orientation and set it on the camera. With this, you can properly change orientation even when device orientation is locked.

Keywords

FAQs

Last updated on 15 Jan 2020

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc