triniwiz / nativescript-videorecorder

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

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).

Additional parameters for Android:

Additional parameters for iOS:

VideoRecorder attributes:

VideoRecorder methods:

Promises above can be rejected with:

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

Method Default Type Description
start() void Starts the camera preview
stop() void Stop the camera preview
startRecording() void Start recording camera preview.
stopRecording() void Stop recording camera preview.
toggleCamera() void Toggles between front or the back camera.
toggleTorch() void Toggles the torch (iOS only for now)
duration int Get the current recording video duration.
cameraPosition BACK void Gets or Sets camera position
outputOrientation PORTRAIT void Gets or Sets output video orientation
isTorchAvailable boolean ReadOnly: is the torch supported for this camera
torch false boolean Enable/Disable torch (iOS only for now)
quality MAX_480P void Gets 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.