@wisdomgarden/media-picker
v1.0.1
Published
This is a Capacitor 2 plugin that provides a Media Picker for selecting images and videos.
Downloads
120
Readme
Media Picker Plugin
This is a Capacitor 2 plugin that provides a Media Picker for selecting images and videos.
Install
npm install @wisdomgarden/media-picker
npx cap sync
or
yarn install @wisdomgarden/media-picker
npx cap sync
Example
// use in web
import { MediaPicker } from '@wisdomgarden/media-picker';
// use in native
import { Plugins } from '@capacitor/core';
const { MediaPicker } = Plugins;
var ret = await MediaPicker.checkAvailability();
console.log('is available', ret.isAvailable);
ret = await MediaPicker.pickMedias({
type: MediaPicker.MEDIA_TYPE.ImageOAndVideo,
maximum: 2
})
if(ret && ret.uris) {
console.log('picked medias', ret.uris);
}
API
checkAvailability
checkAvailability(): Promise<AvailabilityState>;
Get the availability state of the media picker.
Returns: Promise<AvailabilityState>
| Property | Type | Description | | --- | --- | --- | | isAvailable | boolean | Whether the media picker is available |
pickMedias
pickMedias(options: {type: PICK_MEDIA_TYPE, maximum?: number}): Promise<PickMediasResult>;
Pick multiple medias.
| Params | Type | Description | required | default |
| --- | --- | --- | --- | --- |
| type
| PICK_MEDIA_TYPE | The type of media to pick | true | |
| maximum
| number | The maximum number of media to pick | false | 1 |
Returns: Promise<PickMediasResult>
Interfaces
AvailabilityState
| Prop | Type | Description |
| --- | --- | --- |
| isAvailable
| boolean | Whether the media picker is available |
PICK_MEDIA_TYPE
| Prop | Type | Description |
| --- | --- | --- |
| ImageOnly
| string | Only images |
| VideoOnly
| string | Only videos |
| ImageOAndVideo
| string | Images and videos |
PickMediasResult
| Prop | Type | Description |
| --- | --- | --- |
| uris
| string[] | The uris of the picked media or undefined if no media is picked |