or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

app-component.mdbiometric-auth.mdbluetooth.mddevice-system.mdevents.mdindex.mdlocation-maps.mdmedia-camera.mdnative-integration.mdnavigation.mdnetwork.mdstorage-filesystem.mdui.mdutilities.md
tile.json

media-camera.mddocs/

Media & Camera APIs

Comprehensive image, video, audio processing and camera integration capabilities.

Capabilities

Image Operations

Choose, preview, and manipulate images from camera or gallery.

/**
 * Choose image from camera or gallery
 * @param options - Image selection options
 */
function chooseImage(options?: ChooseImageOptions): void;

/**
 * Preview image with zoom and swipe functionality
 * @param options - Preview options
 */
function previewImage(options: PreviewImageOptions): void;

/**
 * Get image information including dimensions and file size
 * @param options - Get image info options
 */
function getImageInfo(options: GetImageInfoOptions): void;

/**
 * Compress image to reduce file size
 * @param options - Compression options
 */
function compressImage(options: CompressImageOptions): void;

/**
 * Save image to device photo album
 * @param options - Save image options
 */
function saveImageToPhotosAlbum(options: SaveImageToPhotosAlbumOptions): void;

interface ChooseImageOptions {
  count?: number; // Default 9
  sizeType?: ('original' | 'compressed')[];
  sourceType?: ('album' | 'camera')[];
  extension?: string[];
  success?: (result: ChooseImageResult) => void;
  fail?: (error: any) => void;
  complete?: () => void;
}

interface ChooseImageResult {
  tempFilePaths: string[];
  tempFiles: ImageFile[];
}

interface ImageFile {
  path: string;
  size: number;
  name: string;
  type: string;
}

interface PreviewImageOptions {
  current?: string;
  urls: string[];
  indicator?: 'default' | 'number' | 'none';
  loop?: boolean;
  success?: (result: any) => void;
  fail?: (error: any) => void;
  complete?: () => void;
}

interface GetImageInfoOptions {
  src: string;
  success?: (result: ImageInfoResult) => void;
  fail?: (error: any) => void;
  complete?: () => void;
}

interface ImageInfoResult {
  width: number;
  height: number;
  path: string;
  orientation: 'up' | 'down' | 'left' | 'right' | 'up-mirrored' | 'down-mirrored' | 'left-mirrored' | 'right-mirrored';
  type: string;
}

Usage Examples:

import uni from "@dcloudio/uni-app-plus";

// Choose image from camera or gallery
uni.chooseImage({
  count: 3,
  sizeType: ['compressed'],
  sourceType: ['album', 'camera'],
  success: (res) => {
    console.log('Selected images:', res.tempFilePaths);
    
    // Preview first image
    uni.previewImage({
      current: res.tempFilePaths[0],
      urls: res.tempFilePaths
    });
    
    // Get image info
    uni.getImageInfo({
      src: res.tempFilePaths[0],
      success: (info) => {
        console.log('Image dimensions:', info.width, 'x', info.height);
      }
    });
  }
});

// Compress images
uni.compressImage({
  src: '/path/to/image.jpg',
  quality: 80,
  success: (res) => {
    console.log('Compressed image:', res.tempFilePath);
    console.log('Original size:', res.size);
  }
});

// Save image to album
uni.saveImageToPhotosAlbum({
  filePath: '/path/to/image.jpg',
  success: () => {
    uni.showToast({
      title: 'Image saved to album',
      icon: 'success'
    });
  }
});

Video Operations

Record, choose, and process video files.

/**
 * Choose video from camera or gallery
 * @param options - Video selection options
 */
function chooseVideo(options?: ChooseVideoOptions): void;

/**
 * Get video file information
 * @param options - Get video info options
 */
function getVideoInfo(options: GetVideoInfoOptions): void;

/**
 * Compress video to reduce file size
 * @param options - Video compression options
 */
function compressVideo(options: CompressVideoOptions): void;

/**
 * Save video to device photo album
 * @param options - Save video options
 */
function saveVideoToPhotosAlbum(options: SaveVideoToPhotosAlbumOptions): void;

/**
 * Create video context for video component control
 * @param videoId - Video component ID
 * @returns VideoContext instance
 */
function createVideoContext(videoId: string): VideoContext;

interface ChooseVideoOptions {
  sourceType?: ('album' | 'camera')[];
  compressed?: boolean;
  maxDuration?: number;
  camera?: 'back' | 'front';
  success?: (result: ChooseVideoResult) => void;
  fail?: (error: any) => void;
  complete?: () => void;
}

interface ChooseVideoResult {
  tempFilePath: string;
  duration: number;
  size: number;
  height: number;
  width: number;
  name: string;
}

interface VideoContext {
  play(): void;
  pause(): void;
  seek(position: number): void;
  stop(): void;
  sendDanmu(danmu: DanmuOptions): void;
  playbackRate(rate: number): void;
  requestFullScreen(options?: FullScreenOptions): void;
  exitFullScreen(): void;
  showStatusBar(): void;
  hideStatusBar(): void;
}

Audio Management

Comprehensive audio recording and playback capabilities.

/**
 * Get audio recorder manager for recording control
 * @returns RecorderManager instance
 */
function getRecorderManager(): RecorderManager;

/**
 * Get background audio manager for background playback
 * @returns BackgroundAudioManager instance
 */
function getBackgroundAudioManager(): BackgroundAudioManager;

/**
 * Create audio context for audio component control
 * @param audioId - Audio component ID
 * @returns AudioContext instance
 */
function createAudioContext(audioId: string): AudioContext;

/**
 * Create inner audio context for programmatic audio control
 * @returns InnerAudioContext instance
 */
function createInnerAudioContext(): InnerAudioContext;

interface RecorderManager {
  start(options: RecordOptions): void;
  pause(): void;
  resume(): void;
  stop(): void;
  onStart(callback: () => void): void;
  onPause(callback: () => void): void;
  onStop(callback: (result: RecordResult) => void): void;
  onFrameRecorded(callback: (result: FrameRecordedResult) => void): void;
  onError(callback: (error: RecordError) => void): void;
  onInterruptionBegin(callback: () => void): void;
  onInterruptionEnd(callback: () => void): void;
}

interface BackgroundAudioManager {
  duration: number;
  currentTime: number;
  paused: boolean;
  src: string;
  startTime: number;
  title: string;
  epname: string;
  singer: string;
  coverImgUrl: string;
  webUrl: string;
  protocol: string;
  play(): void;
  pause(): void;
  stop(): void;
  seek(position: number): void;
  onCanplay(callback: () => void): void;
  onPlay(callback: () => void): void;
  onPause(callback: () => void): void;
  onStop(callback: () => void): void;
  onEnded(callback: () => void): void;
  onTimeUpdate(callback: () => void): void;
  onError(callback: (error: any) => void): void;
}

interface InnerAudioContext {
  src: string;
  startTime: number;
  autoplay: boolean;
  loop: boolean;
  obeyMuteSwitch: boolean;
  volume: number;
  duration: number;
  currentTime: number;
  paused: boolean;
  buffered: number;
  play(): void;
  pause(): void;
  stop(): void;
  seek(position: number): void;
  destroy(): void;
  onCanplay(callback: () => void): void;
  onPlay(callback: () => void): void;
  onPause(callback: () => void): void;
  onStop(callback: () => void): void;
  onEnded(callback: () => void): void;
  onTimeUpdate(callback: () => void): void;
  onError(callback: (error: any) => void): void;
  onWaiting(callback: () => void): void;
  onSeeking(callback: () => void): void;
  onSeeked(callback: () => void): void;
}

Usage Examples:

// Record audio
const recorderManager = uni.getRecorderManager();

recorderManager.onStart(() => {
  console.log('Recording started');
});

recorderManager.onStop((res) => {
  console.log('Recording stopped:', res.tempFilePath);
  console.log('Duration:', res.duration);
});

recorderManager.start({
  duration: 60000,
  sampleRate: 44100,
  numberOfChannels: 1,
  encodeBitRate: 192000,
  format: 'aac'
});

// Background audio playback
const backgroundAudio = uni.getBackgroundAudioManager();
backgroundAudio.title = 'Song Title';
backgroundAudio.singer = 'Artist Name';
backgroundAudio.coverImgUrl = 'https://example.com/cover.jpg';
backgroundAudio.src = 'https://example.com/music.mp3';

backgroundAudio.onPlay(() => {
  console.log('Background audio playing');
});

// Inner audio for app sounds
const innerAudio = uni.createInnerAudioContext();
innerAudio.src = '/static/sounds/notification.mp3';
innerAudio.onError((error) => {
  console.error('Audio error:', error);
});
innerAudio.play();

Camera Control

Direct camera control for custom camera interfaces.

/**
 * Create camera context for camera component control
 * @returns CameraContext instance
 */
function createCameraContext(): CameraContext;

interface CameraContext {
  takePhoto(options: TakePhotoOptions): void;
  startRecord(options: StartRecordOptions): void;
  stopRecord(options?: StopRecordOptions): void;
  onCameraFrame(callback: (frame: CameraFrame) => void): void;
}

interface TakePhotoOptions {
  quality?: 'high' | 'normal' | 'low';
  success?: (result: TakePhotoResult) => void;
  fail?: (error: any) => void;
  complete?: () => void;
}

interface TakePhotoResult {
  tempImagePath: string;
}

File Selection

Choose various file types from device storage.

/**
 * Choose file from device storage
 * @param options - File selection options
 */
function chooseFile(options?: ChooseFileOptions): void;

interface ChooseFileOptions {
  count?: number;
  type?: 'all' | 'video' | 'image';
  extension?: string[];
  success?: (result: ChooseFileResult) => void;
  fail?: (error: any) => void;
  complete?: () => void;
}

interface ChooseFileResult {
  tempFilePaths: string[];
  tempFiles: FileInfo[];
}

interface FileInfo {
  path: string;
  size: number;
  name: string;
  type: string;
}

Types

Media Types

interface CompressImageOptions {
  src: string;
  quality?: number; // 0-100
  width?: number;
  height?: number;
  compressedWidth?: number;
  compressedHeight?: number;
  rotate?: number;
  success?: (result: CompressImageResult) => void;
  fail?: (error: any) => void;
  complete?: () => void;
}

interface CompressImageResult {
  tempFilePath: string;
  size: number;
}

interface SaveImageToPhotosAlbumOptions {
  filePath: string;
  success?: (result: any) => void;
  fail?: (error: any) => void;
  complete?: () => void;
}

interface RecordOptions {
  duration?: number;
  sampleRate?: number;
  numberOfChannels?: number;
  encodeBitRate?: number;
  format?: 'aac' | 'mp3';
  frameSize?: number;
  audioSource?: 'auto' | 'buildInMic' | 'headsetMic' | 'mic' | 'camcorder' | 'voice_communication' | 'voice_recognition';
}

interface RecordResult {
  tempFilePath: string;
  duration: number;
  fileSize: number;
}

interface DanmuOptions {
  text: string;
  color?: string;
  time?: number;
}

interface FullScreenOptions {
  direction?: 0 | 90 | -90;
}