onymosMedia.select
To access the Media or Camera, we call the select function, usually in response to an event like clicking on a Camera icon.
OnymosMedia.select(
callId,
PICTURE_SOURCE_TYPE,
// Example: OnymosMediaConstants.PictureSourceType.CAMERA
MEDIA_TYPE,
// Example: OnymosMediaConstants.MediaType.ALLMEDIA
(mediaURI, mediaObject) => {
/* ------
mediaObject = {
mediaSize: size_in_bytes,
mediaType: mp4 or jpeg,
mediaUrl: localUrl to media,
duration: time in seconds, if video file
};
------ */
console.log(mediaURI);
},
(error) => {
console.log(error);
},
options
);
callId
To identify each call to select Media. In most cases, only one invocation will be required, and so use ‘1’. A special case example is, if your app has ‘Your Picture’, ‘Your spouse picture’, with separate camera icons next to each to select each picture, use callId of ‘1’, and ‘2’.
PICTURE_SOURCE_TYPE
[OC] = OnymosMediaConstants
[OC].PictureSourceType.PHOTOLIBRARY
Lets users select Media from the Device Media library.
[OC].PictureSourceType.CAMERA
Opens the camera app and lets user to directly take a picture or video.
MEDIA_TYPE
[OC] = OnymosMediaConstants
[OC].MediaType.PICTURE
Displays only Photos in Device Media library for user selection (or) Capture a Photo.
[OC].MediaType.VIDEO
Displays only Videos in Device Media Library for user selection (or) Capture a Video.
[OC].MediaType.ALLMEDIA
Displays both Photos and Videos in Device Media library for user selection.
options
saveToPhotoAlbum
When PICTURE_SOURCE_TYPE is [OC].PictureSourceType.CAMERA, setting saveToPhotoAlbum to true will allow for the captured Photo to be saved to the device’s photo album.
Example: { saveToPhotoAlbum: true }
videoCaptureDuration
When PICTURE_SOURCE_TYPE is [OC].PictureSourceType.CAMERA, and MEDIA_TYPE is [OC].MediaType.VIDEO, limit the duration of video the user can capture, with this videoCaptureDuration (seconds) setting.
Example: { videoCaptureDuration: 15 }
Note:
This feature is not supported by some Android device manufacturers.
onymosMedia.cancelSelect
To cancel the previously made selection, we call the cancelSelect function, usually in response to an event like clicking on a Cancel icon.
This call clears the callId and removes the association with the selected Media. In addition this function also clears the selected Media URI, thumbNail and all intermediate media stores to clear valuable memory space in your app.
OnymosMedia.cancelSelect(callId);
callId
Use the same callId used during OnymosMedia.select to cancel that selection.
onymosMedia.getThumbnail
To display a thumbnail of the photo or video (the first frame of the video) we call the getThumbnail function, usually called in the success callback of the select function above.
OnymosMedia.getThumbnail(callId)
callId
Use the same callId used during OnymosMedia.select to obtain a thumbnail for that media.
onymosMedia.getMediaType
To know the type of media the user has selected (mp4 or jpeg). We can find that by calling the getMediaType function, usually called in the success callback of the select function above.
OnymosMedia.getMediaType(callId);
callId
Use the same callId used during OnymosMedia.select to obtain the media type of that selected media.
onymosMedia.upload
To upload the selected Media to Onymos Hosting, we call the upload function, usually in response to an event like clicking on a Send button.
The uploaded Photos will not have EXIF information for better Privacy compliance.
OnymosMedia.upload(
callId,
tagsArray,
(status) => {
console.log(status);
},
(error) => {
console.log(error);
},
options
);
callId
Use the same callId used during OnymosMedia.select to upload that media.
tagsArray
Array of Strings: Up to 5 strings (at least 1 is required) can be used to tag a Media. These set of tags will be used to find Media later. Most frequently, a unique Id alone is used as a Tag. However, you can use something like,
var tagsArray = ‘Fast, Red, European, Car’.split(/[\s,]+/);
Note:
tagsArray strings cannot contain ASCII control characters 0-31, 127, and any of “$, #, /, ., {, }, [, ], (, )” characters.
tagsArray strings cannot be longer than 512 characters.
options
mediaResizeFactor
Use either mediaResizeFactor or targetDeviceFactor.
Provide a value from 1-100 for the % of original size you want to resize the media data to, before upload.
Note:
Actual Level of Resizing achieved depends on variety of factors including actual data in the media, device and OS variations.
optimizerBySourceSize
Default: true.
To be used in conjunction with mediaResizeFactor. When true, the resizing performed will take into account the size of the original photo or video.
For example, specifying a particular mediaResizeFactor (say 50) on a large 1920×1080 photo and a medium 1280×720 photo will both upload a 960×540 resized photo, when optimizeBySourceSize is set to true.
targetDeviceFactor
Use either targetDeviceFactor or mediaResizeFactor.
[OC] = OnymosMediaConstants
[OC].TargetDeviceFactor.MOBILE
Uploads a standard sized media suited for Mobile devices.
[OC].TargetDeviceFactor.TABLET
Uploads a standard sized media suited for Tablet devices.
[OC].TargetDeviceFactor.DESKTOP
Uploads a standard sized media suited for Desktop devices.
thumbnailResizeFactor
If this option is not specified or if its value is set to NULL, thumbnail is not uploaded. A value from 1-100 can be specified for the % of original size you want to resize the thumbnail media data to, before upload.
Note:
In general, original Photo thumbnails are larger than Video thumbnails. To obtain equal sized Photo and Video thumbnail data, you may have to use a lower resizeFactor (% of original size) for Photo thumbnails, than what you use for Video thumbnails.
Actual level of Resizing achieved depends on variety of factors including actual data in the media, device and OS variations.
uploadSizeLimit
For performance and stability reasons, as well as your app users’ experience (e.g., time taken to upload, memory/cpu/network used, etc.), you can specify a value in MB (Megabytes) that you want to restrict the upload file to. If a file to be uploaded, after applying the optional mediaResizeFactor, exceeds this uploadSizeLimit this upload function will return an error.
{
targetDeviceFactor: OnymosMediaConstants.TargetDeviceFactor.MOBILE,
mediaResizeFactor: 80,
thumbnailResizeFactor: 20,
uploadSizeLimit: 15
}
onymosMedia.stopUpload
To stop an Upload currently in-progress, we call the stopUpload function, usually in response to an event like clicking on a Stop icon.
Upon a successful stop, the failureCallback of the upload function will trigger with an error message, ‘Picture upload to Cloud failed’.
OnymosMedia.stopUpload(callId);
callId
Use the same callId used during OnymosMedia.upload to stop that upload.
onymosMedia.getUploadProgress
To track the progress of a previous Upload call, we call the getUploadProgress function, usually right after a call to the upload function.
OnymosMedia.getUploadProgress(
callId,
(statusObject) => {
/* ------
statusObject = {
percent: Percentage or -1, if total is being determined,
uploaded: Size in bytes,
total: Size in bytes or 'Determining...'
};
------ */
},
(error) => {
console.log(error);
}
);
callId
Use the same callId used during OnymosMedia.upload to track progress of that upload.
onymosMedia.search
To find previously uploaded Media at either Onymos Hosting or your cloud hosting provider, we call the search function.
OnymosMedia.search(
tagsArray,
(resultsArray) => {
/* ------
resultsArray = [{
fileName: System generated name,
mediaSize: Size in bytes,
mediaType: MP4, JPEG, etc,
mediaUrl: Secure URL,
thumbnailUrl: Secure URL,
uploadTime: Unix epoch time
}];
------ */
},
(error) => {
console.log(error);
},
options
);
tagsArray
Array of Strings: Up to 5 strings (at least 1 is required) can be used to tag a Media. These set of tags will be used to find Media later. Most frequently, a unique Id alone is used as a Tag. However, you can use something like,
var tagsArray = ‘Fast, Red, European, Car’.split(/[\s,]+/);
Note:
tagsArray strings cannot contain ASCII control characters 0-31, 127, and any of “$, #, /, ., {, }, [, ], (, )” characters.
tagsArray strings cannot be longer than 512 characters.
options
resultsValidityTime
The mediaLocation and thumbnailLocation (secure URL-s) returned by this search function, will be valid only for the number of seconds specified in this parameter.
searchResultsLimit
For your app’s search performance, you can limit the number of results returned by this search function, by setting an integer value to this parameter.
{
resultsValidityTime: 1800,
searchResultsLimit: 5
}