Skip to content

Cordova wrapper class to help standardize getting photos, videos and audio from your library or by recording and uploading multiple files at once.

License

Notifications You must be signed in to change notification settings

WebsiteBeaver/cordova-media-upload

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Prerequisites

You'll need to use the following Cordova plugins:

To add these plugins, run the following commands on your terminal.

cordova plugin add cordova-plugin-camera
cordova plugin add cordova-plugin-media-capture
cordova plugin add cordova-plugin-file
cordova plugin add cordova-plugin-video-editor

This is all you need if you're just using the Cordova Media Upload class, which can be found in js/cordova-media-upload.js. This entire repo is that plus a messaging demo you can try out on a blank Cordova project and uses Framework7. The demo also uses the Cordova Streaming Media plugin to preview videos in the messaging system. Again, this is not necessary if you're just using this class.

cordova plugin add cordova-plugin-streaming-media

CordovaMediaUpload

Cordova wrapper class to help standardize getting photos, videos and audio from your library or by recording and uploading multiple files at once.

Kind: global class

new CordovaMediaUpload([optionsObj])

CordovaMediaUpload constructor

Param Type Default Description
[optionsObj] object {} Set options.
[optionsObj.imageWidth] int Image width
[optionsObj.imageHeight] int Image height
[optionsObj.imageQuality] int 50 Image quality as a percent
[optionsObj.videoWidth] int Video width
[optionsObj.videoHeight] int Video height
[optionsObj.videoBitRate] int 1000000 Video bit rate in bits, defaults to 1 megabit (1000000)

Example

const cmu = new CordovaMediaUpload({
  imageWidth: 700,
  imageHeight: 700,
  videoWidth: 1920,
  videoHeight: 1080
});

cordovaMediaUpload.capturePhoto([newOptionsObj]) ⇒ promise

Take a photo with the camera.

Kind: instance method of CordovaMediaUpload
Fulfil: string - Local file URI for photo.
Reject: Error - Rejected promise with message. No message if user cancelled.

Param Type Default Description
[newOptionsObj] object {} New options to set or change.

Example

cmu.capturePhoto()
  .then(fileUri => {})
  .catch(error => { if(error) console.log('error'); });

cordovaMediaUpload.getPhoto([newOptionsObj]) ⇒ promise

Get existing photo from library.

Kind: instance method of CordovaMediaUpload
Fulfil: string - Local file URI for photo.
Reject: Error - Rejected promise with message. No message if user cancelled.

Param Type Default Description
[newOptionsObj] object {} New options to set or change.

Example

cmu.getPhoto()
  .then(fileUri => {})
  .catch(error => { if(error) console.log('error'); });

cordovaMediaUpload.captureVideo([newOptionsObj]) ⇒ promise

Record video.

Kind: instance method of CordovaMediaUpload
Fulfil: array [string imageUri, string videoUri] - The image and video file URI.
Reject: Error - Rejected promise with message. No message if user cancelled.

Param Type Default Description
[newOptionsObj] object {} New options to set or change.

Example

cmu.captureVideo()
  .then([imageUri, videoUri] => {})
  .catch(error => { if(error) console.log('error'); });

cordovaMediaUpload.getVideo([newOptionsObj]) ⇒ promise

Get existing video from library.

Kind: instance method of CordovaMediaUpload
Fulfil: array [string imageUri, string videoUri] - The image and video file URI.
Reject: Error - Rejected promise with message. No message if user cancelled.

Param Type Default Description
[newOptionsObj] object {} New options to set or change.

Example

cmu.getVideo()
  .then([imageUri, videoUri] => {})
  .catch(error => { if(error) console.log('error'); });

cordovaMediaUpload.captureAudio() ⇒ promise

Record audio.

Kind: instance method of CordovaMediaUpload
Fulfil: string - Local file URI for photo.
Reject: Error - Rejected promise with message. No message if user cancelled.
Example

cmu.captureAudio()
  .then(fileUri => {})
  .catch(error => { if(error) console.log('error'); });

cordovaMediaUpload.transcodeVideos(videoUris, [newOptionsObj]) ⇒ promise

Transcoode video.

Kind: instance method of CordovaMediaUpload
Fulfil: string[] - Array of transcoded video URIs.
Reject: Error - Rejected promise with message. No message if user cancelled.

Param Type Default Description
videoUris Array.<string> | string Local video URIs to transcode.
[newOptionsObj] object {} New options to set or change.

Example

cmu.transcodeVideos()
  .then(videoUris => {})
  .catch(error => { if(error) console.log('error'); });

cordovaMediaUpload.uploadFiles(serverUrl, paramsObj, fileUris, [videoUriArrObj]) ⇒ promise

Upload files.

Kind: instance method of CordovaMediaUpload
Fulfil: object[] - JSON data from server.
Reject: Error - Fail to convert files to blobs.

Param Type Default Description
serverUrl string URL to upload files to.
paramsObj object parameters to send to server.
fileUris Array.<string> | string Local video URIs to upload.
[videoUriArrObj] object {} The video and thumbnail URI array object
[videoUriArrObj.thumbs] Array.<string> The video thumbnail URIs
[videoUriArrObj.videos] Array.<string> The video URIs

Example

const serverUrl = 'https://url-to-upload-files';
const paramsObj = {}; //Parameters sent to server
cmu.uploadFiles(serverUrl, paramsObj, fileUris)
  .then(data => {})
  .catch(error => { if(error) console.log('error'); });

cordovaMediaUpload.deleteFiles(fileUris) ⇒ promise

Delete files.

Kind: instance method of CordovaMediaUpload
Fulfil: - The file URI has been deleted.
Reject: Error - Rejected promise with message.

Param Type Description
fileUris Array.<string> | string Local video URI to transcode.

Example

cmu.deleteFiles(fileUris)
  .then(() => {})
  .catch(error => { if(error) console.log('error'); });

About

Cordova wrapper class to help standardize getting photos, videos and audio from your library or by recording and uploading multiple files at once.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published