chooseMedia(params: Object)

Requires:
BaseKit≥2.5.0@ray-js/ray≥0.5.9
Platforms:
iOSAndroid
import { chooseMedia } from '@ray-js/ray';

// Promise usage
try {
  const res = await chooseMedia({ ...params });
  console.log(res);
} catch (err) {
  console.log(err.errorMsg);
}

Description

Capture or select images or videos from the album
Permissions: [scope.camera, scope.writePhotosAlbum]

Parameters

PropertyTypeRequiredDefaultDescriptionBaseKit Since
countnumberNo9Maximum number of files to select. Note: On Android 13 and above, the system image picker is used and this field has no effect-
mediaTypestringNo"image"Selection type, default is image 'image' can only capture or select images 'video' can only capture or select videos-
sourceTypestring[]No["album", "camera"]Sources for selecting images/videos, default ['album', 'camera'] 'album' select from album 'camera' capture using the camera-
maxDurationnumberNo10Maximum recording duration for captured video in seconds, default 10s Range: 3s to 60s. No limit for videos from the album-
isFetchVideoFilebooleanNotrueiOS only Whether to copy the video: Default true: copy the video and return the copied video path and cover path false: do not copy; return the album video path and cover image pathv3.14.2
isClipVideobooleanNofalseiOS only Whether to trim videos selected from the album Default false: do not trimv3.14.2
maxClipDurationnumberNo60Maximum trim length in seconds, default 60s Takes effect only when isClipVideo is true Range: 60s to 600s. Videos shorter than 15s are not trimmedv3.14.2
isGetAlbumFileNamebooleanNofalseiOS only Whether to use the exported filename identical to the album filename Default false: use a unique filename each timev3.14.2
isClipVideoAndroidbooleanNotrueThis parameter is only effective on Android. 芯图定制. To be merged into isClipVideo later Whether the video selected from the album needs cropping Default is true: crop the video, consistent with the original behaviorv3.32.13
complete() => voidNo-Completion callback (executed on both success and failure)-
success(params: Object) => voidNo-Callback on successful API call-
fail(params: Object) => voidNo-Failure callback-
success callback parameters
PropertyTypeDescriptionBaseKit Since
typestringFile type 'image' image 'video' videov3.2.6
List of local temporary filesv3.2.6
fail callback parameters
PropertyTypeDescription
errorMsgstringError message
errorCodestring | numberError code
Error extension

Return Value

None

Examples

import { chooseMedia } from '@ray-js/ray'

// Capture or select images/videos (invokes the system picker; manual selection required)
chooseMedia({
  count: 1,
  mediaType: "image",
  sourceType: ["album", "camera"],
  maxDuration: 10,
  success: data => console.log("Selected:", data.type, data.tempFiles),
  fail: error => console.error(error),
});