Native plugin wrappers for Cordova and Ionic with TypeScript, ES6+, Promise and Observable support
—
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Pending
The risk profile of this skill
Comprehensive camera functionality, media capture, and photo/video management with full configuration options for mobile applications.
Take pictures and access photo library with extensive configuration options for quality, source, and format.
/**
* Camera options interface for configuring picture capture
*/
interface CameraOptions {
/** Picture quality in range 0-100. Default is 50 */
quality?: number;
/**
* Choose the format of the return value
* DATA_URL: 0 - Return image as base64-encoded string
* FILE_URI: 1 - Return image file URI (default)
* NATIVE_URI: 2 - Return image native URI
*/
destinationType?: number;
/**
* Set the source of the picture
* PHOTOLIBRARY: 0 - Choose from photo library
* CAMERA: 1 - Take picture from camera (default)
* SAVEDPHOTOALBUM: 2 - Choose from saved photo album
*/
sourceType?: number;
/** Allow simple editing of image before selection */
allowEdit?: boolean;
/**
* Choose the returned image file's encoding
* JPEG: 0 - Return JPEG encoded image (default)
* PNG: 1 - Return PNG encoded image
*/
encodingType?: number;
/** Width in pixels to scale image. Must be used with targetHeight */
targetWidth?: number;
/** Height in pixels to scale image. Must be used with targetWidth */
targetHeight?: number;
/**
* Set the type of media to select from
* PICTURE: 0 - Allow selection of still pictures only (default)
* VIDEO: 1 - Allow selection of video only, always returns FILE_URI
* ALLMEDIA: 2 - Allow selection from all media types
*/
mediaType?: number;
/** Rotate the image to correct for the orientation of the device */
correctOrientation?: boolean;
/** Save the image to the photo album on the device after capture */
saveToPhotoAlbum?: boolean;
/**
* Choose the camera to use
* BACK: 0 - Use the back-facing camera (default)
* FRONT: 1 - Use the front-facing camera
*/
cameraDirection?: number;
/** iOS-only options that specify popover location in iPad */
popoverOptions?: CameraPopoverOptions;
}
/**
* iOS-only parameters for iPad popover when selecting images
*/
interface CameraPopoverOptions {
x: number;
y: number;
width: number;
height: number;
/**
* Direction the arrow on the popover should point
* ARROW_UP: 1, ARROW_DOWN: 2, ARROW_LEFT: 4, ARROW_RIGHT: 8, ARROW_ANY: 15
*/
arrowDir: number;
}
/**
* Camera class providing static methods for picture capture
*/
class Camera {
/** Return format constants */
static DestinationType: {
/** Return base64 encoded string (memory intensive) */
DATA_URL: 0;
/** Return file uri (content://media/external/images/media/2 for Android) */
FILE_URI: 1;
/** Return native uri (asset-library:// for iOS) */
NATIVE_URI: 2;
};
/** Encoding type constants */
static EncodingType: {
/** Return JPEG encoded image */
JPEG: 0;
/** Return PNG encoded image */
PNG: 1;
};
/** Media type constants */
static MediaType: {
/** Allow selection of still pictures only */
PICTURE: 0;
/** Allow selection of video only */
VIDEO: 1;
/** Allow selection from all media types */
ALLMEDIA: 2;
};
/** Picture source constants */
static PictureSourceType: {
/** Choose image from picture library */
PHOTOLIBRARY: 0;
/** Take picture from camera */
CAMERA: 1;
/** Choose image from saved photo album */
SAVEDPHOTOALBUM: 2;
};
/** Camera direction constants */
static Direction: {
/** Use the back-facing camera */
BACK: 0;
/** Use the front-facing camera */
FRONT: 1;
};
/** Popover arrow direction constants (iOS) */
static PopoverArrowDirection: {
ARROW_UP: 1;
ARROW_DOWN: 2;
ARROW_LEFT: 4;
ARROW_RIGHT: 8;
ARROW_ANY: 15;
};
/**
* Take a picture or video, or load one from the library
* @param options Optional camera configuration options
* @returns Promise resolving to Base64 encoding or image file URI
*/
static getPicture(options?: CameraOptions): Promise<any>;
/**
* Remove intermediate image files from temporary storage (iOS only)
* Only applies when sourceType equals CAMERA and destinationType equals FILE_URI
* @returns Promise indicating cleanup completion
*/
static cleanup(): Promise<any>;
}Usage Examples:
import { Camera, CameraOptions } from 'ionic-native';
// Basic camera usage
const basicOptions: CameraOptions = {
quality: 75,
destinationType: Camera.DestinationType.FILE_URI,
sourceType: Camera.PictureSourceType.CAMERA,
encodingType: Camera.EncodingType.JPEG
};
Camera.getPicture(basicOptions).then((imageData) => {
// imageData is the file URI
const imageUri = imageData;
console.log('Image saved to: ' + imageUri);
}, (err) => {
console.error('Camera error: ' + err);
});
// High quality photo with front camera
const selfieOptions: CameraOptions = {
quality: 100,
destinationType: Camera.DestinationType.FILE_URI,
sourceType: Camera.PictureSourceType.CAMERA,
encodingType: Camera.EncodingType.JPEG,
targetWidth: 600,
targetHeight: 600,
cameraDirection: Camera.Direction.FRONT,
correctOrientation: true,
saveToPhotoAlbum: true
};
// Select from photo library
const libraryOptions: CameraOptions = {
quality: 100,
destinationType: Camera.DestinationType.FILE_URI,
sourceType: Camera.PictureSourceType.PHOTOLIBRARY,
mediaType: Camera.MediaType.PICTURE,
allowEdit: true
};
// Get base64 encoded image (use sparingly due to memory usage)
const base64Options: CameraOptions = {
quality: 50,
destinationType: Camera.DestinationType.DATA_URL,
sourceType: Camera.PictureSourceType.CAMERA
};
Camera.getPicture(base64Options).then((imageData) => {
const base64Image = 'data:image/jpeg;base64,' + imageData;
// Use base64Image in img tag or upload
}, (err) => {
console.error('Camera error: ' + err);
});Capture audio, video, and images with detailed configuration and metadata.
/**
* Media file information returned from capture operations
*/
interface MediaFile {
/** Name of the file, without path information */
name: string;
/** Full path of the file, including the name */
fullPath: string;
/** File's mime type */
type: string;
/** Date and time when file was last modified */
lastModifiedDate: Date;
/** Size of the file, in bytes */
size: number;
/**
* Retrieves format information about the media capture file
* @param successCallback Success callback with ConfigurationData
* @param errorCallback Error callback
*/
getFormatData(
successCallback: (data: ConfigurationData) => void,
errorCallback?: (error: CaptureError) => void
): void;
}
/**
* Format information about captured media
*/
interface ConfigurationData {
/** Media type (audio/video/image) */
type: string;
/** Height of the image or video in pixels */
height: number;
/** Width of the image or video in pixels */
width: number;
}
/**
* Capture error information
*/
interface CaptureError {
/** Error code */
code: number;
/** Error message */
message: string;
}
/**
* Audio capture configuration options
*/
interface CaptureAudioOptions {
/** Maximum number of audio clips to capture (default: 1) */
limit?: number;
/** Maximum duration of audio clip in seconds */
duration?: number;
}
/**
* Image capture configuration options
*/
interface CaptureImageOptions {
/** Maximum number of images to capture (default: 1) */
limit?: number;
}
/**
* Video capture configuration options
*/
interface CaptureVideoOptions {
/** Maximum number of video clips to capture (default: 1) */
limit?: number;
/** Maximum duration of video clip in seconds */
duration?: number;
/** Video quality: 0 = low, 1 = high */
quality?: number;
}
/**
* MediaCapture class for capturing media files
*/
class MediaCapture {
/**
* Start audio recording application to capture audio clips
* @param options Audio capture configuration options
* @returns Promise resolving to array of captured MediaFile objects
*/
static captureAudio(options?: CaptureAudioOptions): Promise<MediaFile[]>;
/**
* Start camera application to capture images
* @param options Image capture configuration options
* @returns Promise resolving to array of captured MediaFile objects
*/
static captureImage(options?: CaptureImageOptions): Promise<MediaFile[]>;
/**
* Start video recorder application to capture video clips
* @param options Video capture configuration options
* @returns Promise resolving to array of captured MediaFile objects
*/
static captureVideo(options?: CaptureVideoOptions): Promise<MediaFile[]>;
}Usage Examples:
import { MediaCapture, CaptureAudioOptions, CaptureVideoOptions, CaptureImageOptions } from 'ionic-native';
// Capture single audio clip
const audioOptions: CaptureAudioOptions = { limit: 1, duration: 30 };
MediaCapture.captureAudio(audioOptions).then((audioFiles) => {
const audioFile = audioFiles[0];
console.log('Audio file: ' + audioFile.fullPath);
console.log('Duration: ' + audioFile.size + ' bytes');
}, (err) => {
console.error('Audio capture error: ' + err);
});
// Capture video with quality settings
const videoOptions: CaptureVideoOptions = {
limit: 1,
duration: 60,
quality: 1 // High quality
};
MediaCapture.captureVideo(videoOptions).then((videoFiles) => {
const videoFile = videoFiles[0];
console.log('Video file: ' + videoFile.fullPath);
// Get format information
videoFile.getFormatData((data) => {
console.log('Video dimensions: ' + data.width + 'x' + data.height);
});
}, (err) => {
console.error('Video capture error: ' + err);
});
// Capture multiple images
const imageOptions: CaptureImageOptions = { limit: 3 };
MediaCapture.captureImage(imageOptions).then((imageFiles) => {
imageFiles.forEach((file, index) => {
console.log(`Image ${index + 1}: ${file.fullPath}`);
});
}, (err) => {
console.error('Image capture error: ' + err);
});Display photos in a native full-screen viewer with zoom and sharing capabilities.
/**
* PhotoViewer class for displaying images in native viewer
*/
class PhotoViewer {
/**
* Display photo in native full-screen viewer
* @param url Image URL (local file path or remote URL)
* @param title Optional title for the photo
* @param options Optional viewer configuration
*/
static show(url: string, title?: string, options?: any): void;
}Usage Examples:
import { PhotoViewer } from 'ionic-native';
// Show local image
PhotoViewer.show('file:///storage/emulated/0/Pictures/photo.jpg', 'My Photo');
// Show remote image
PhotoViewer.show('https://example.com/photo.jpg', 'Remote Photo');
// Show image with options
const options = {
share: true, // Enable sharing button
closeButton: true, // Show close button
copyToReference: true // Enable copy to clipboard
};
PhotoViewer.show('path/to/photo.jpg', 'Photo Title', options);Access and manage the device's photo library with comprehensive metadata and thumbnail support.
/**
* Photo library item information
*/
interface LibraryItem {
/** Unique identifier for the library item */
id: string;
/** Original filename */
fileName: string;
/** Width of image/video */
width: number;
/** Height of image/video */
height: number;
/** Creation date */
creationDate: Date;
/** Location coordinates if available */
latitude?: number;
longitude?: number;
/** Album name */
albumName?: string;
}
/**
* Authorization request options
*/
interface RequestAuthorizationOptions {
/** Request read authorization */
read?: boolean;
/** Request write authorization */
write?: boolean;
}
/**
* Library retrieval options
*/
interface GetLibraryOptions {
/** Number of items per batch */
itemsInChunk?: number;
/** Chunk timeout in milliseconds */
chunkTimeLimitInMilliseconds?: number;
/** Include video files */
includeVideos?: boolean;
/** Include images */
includeImages?: boolean;
/** Include cloud items */
includeCloudSharedAlbums?: boolean;
}
/**
* Thumbnail generation options
*/
interface GetThumbnailOptions {
/** Thumbnail width */
thumbnailWidth?: number;
/** Thumbnail height */
thumbnailHeight?: number;
/** Image quality (0-100) */
quality?: number;
}
/**
* PhotoLibrary class for accessing device photo library
*/
class PhotoLibrary {
/**
* Request authorization to access photo library
* @param options Authorization options
* @returns Promise indicating authorization result
*/
static requestAuthorization(options?: RequestAuthorizationOptions): Promise<void>;
/**
* Get library items as observable stream
* @param options Library retrieval options
* @returns Observable stream of LibraryItem objects
*/
static getLibrary(options?: GetLibraryOptions): Observable<LibraryItem>;
/**
* Get thumbnail for specific photo
* @param photoId Unique photo identifier
* @param options Thumbnail generation options
* @returns Promise resolving to base64 thumbnail data
*/
static getThumbnail(photoId: string, options?: GetThumbnailOptions): Promise<string>;
/**
* Get full-size photo data
* @param photoId Unique photo identifier
* @returns Promise resolving to base64 photo data
*/
static getPhoto(photoId: string): Promise<string>;
/**
* Save image to photo library
* @param url Image URL to save
* @param album Optional album name
* @param options Save options
* @returns Promise indicating save completion
*/
static saveImage(url: string, album?: string, options?: any): Promise<void>;
/**
* Save video to photo library
* @param url Video URL to save
* @param album Optional album name
* @param options Save options
* @returns Promise indicating save completion
*/
static saveVideo(url: string, album?: string, options?: any): Promise<void>;
}Usage Examples:
import { PhotoLibrary, GetLibraryOptions } from 'ionic-native';
// Request authorization and get library
async function loadPhotoLibrary() {
try {
await PhotoLibrary.requestAuthorization({ read: true });
const options: GetLibraryOptions = {
itemsInChunk: 100,
includeImages: true,
includeVideos: false
};
PhotoLibrary.getLibrary(options).subscribe(
(libraryItem) => {
console.log('Photo:', libraryItem.fileName);
// Get thumbnail
PhotoLibrary.getThumbnail(libraryItem.id, {
thumbnailWidth: 150,
thumbnailHeight: 150,
quality: 80
}).then((thumbnail) => {
// Use base64 thumbnail data
const img = document.createElement('img');
img.src = 'data:image/jpeg;base64,' + thumbnail;
});
},
(error) => {
console.error('Library error:', error);
}
);
} catch (error) {
console.error('Authorization error:', error);
}
}
// Save image to photo library
PhotoLibrary.saveImage('file:///path/to/image.jpg', 'My Album').then(() => {
console.log('Image saved to photo library');
}).catch((error) => {
console.error('Save error:', error);
});Play YouTube videos using the native YouTube app for enhanced user experience and performance.
/**
* YouTube Video Player class for native video playback
*/
class YoutubeVideoPlayer {
/**
* Open and play a YouTube video in the native YouTube app
* @param videoId YouTube video ID (from the video URL)
*/
static openVideo(videoId: string): void;
}Usage Examples:
import { YoutubeVideoPlayer } from 'ionic-native';
// Play YouTube video by ID
YoutubeVideoPlayer.openVideo('dQw4w9WgXcQ');
// Extract video ID from YouTube URL and play
const youtubeUrl = 'https://www.youtube.com/watch?v=dQw4w9WgXcQ&t=60s';
const videoId = youtubeUrl.split('v=')[1].split('&')[0];
YoutubeVideoPlayer.openVideo(videoId);
// Play video with video ID from different URL formats
const shortUrl = 'https://youtu.be/dQw4w9WgXcQ';
const shortVideoId = shortUrl.split('/').pop();
YoutubeVideoPlayer.openVideo(shortVideoId);