MediaUtils: {
    isMediaTypeSupported(type): boolean;
    getSupportedMediaTypes(): string[];
    getMediaDevices(): Promise<MediaDeviceInfo[]>;
    getCameras(): Promise<MediaDeviceInfo[]>;
    getMicrophones(): Promise<MediaDeviceInfo[]>;
    getSpeakers(): Promise<MediaDeviceInfo[]>;
    requestCameraAccess(constraints?): Promise<MediaStream>;
    requestMicrophoneAccess(constraints?): Promise<MediaStream>;
    requestScreenAccess(constraints?): Promise<MediaStream>;
    stopMediaStream(stream): void;
    createMediaRecorder(stream, options?): MediaRecorder;
    recordMediaStream(stream, options?): Promise<Blob>;
    takeScreenshot(video): Promise<Blob>;
    blobToBase64(blob): Promise<string>;
    base64ToBlob(base64, type): Blob;
    downloadBlob(blob, filename): void;
    getVideoDuration(file): Promise<number>;
    getVideoDimensions(file): Promise<{
        width: number;
        height: number;
    }>;
    getAudioDuration(file): Promise<number>;
    getImageDimensions(file): Promise<{
        width: number;
        height: number;
    }>;
    resizeImage(file, maxWidth, maxHeight): Promise<Blob>;
    compressImage(file, quality?): Promise<Blob>;
} = ...

Type declaration

  • isMediaTypeSupported:function
    • Checks if the browser supports a specific media type.

      Parameters

      • type: string

        Media type to check (e.g., 'video/mp4')

      Returns boolean

      True if the media type is supported

      Example

      MediaUtils.isMediaTypeSupported('video/mp4'); // true or false
      MediaUtils.isMediaTypeSupported('audio/ogg'); // true or false
  • getSupportedMediaTypes:function
    • Gets the supported media types for the current browser.

      Returns string[]

      Array of supported media types

      Example

      const supported = MediaUtils.getSupportedMediaTypes();
      console.log(supported);
  • getMediaDevices:function
    • Gets the user's media devices (cameras, microphones, speakers).

      Returns Promise<MediaDeviceInfo[]>

      Promise that resolves with an array of media devices

      Example

      const devices = await MediaUtils.getMediaDevices();
      devices.forEach(device => console.log(device.kind, device.label));
  • getCameras:function
    • Gets the user's camera devices.

      Returns Promise<MediaDeviceInfo[]>

      Promise that resolves with an array of camera devices

      Example

      const cameras = await MediaUtils.getCameras();
      cameras.forEach(cam => console.log(cam.label));
  • getMicrophones:function
    • Gets the user's microphone devices.

      Returns Promise<MediaDeviceInfo[]>

      Promise that resolves with an array of microphone devices

      Example

      const microphones = await MediaUtils.getMicrophones();
      microphones.forEach(mic => console.log(mic.label));
  • getSpeakers:function
    • Gets the user's speaker devices.

      Returns Promise<MediaDeviceInfo[]>

      Promise that resolves with an array of speaker devices

      Example

      const speakers = await MediaUtils.getSpeakers();
      speakers.forEach(spk => console.log(spk.label));
  • requestCameraAccess:function
    • Requests access to the user's camera.

      Parameters

      • constraints: MediaStreamConstraints = ...

        Media constraints (default: { video: true })

      Returns Promise<MediaStream>

      Promise that resolves with a MediaStream

      Example

      const stream = await MediaUtils.requestCameraAccess();
      // Attach to video element
      videoElement.srcObject = stream;
  • requestMicrophoneAccess:function
    • Requests access to the user's microphone.

      Parameters

      • constraints: MediaStreamConstraints = ...

        Media constraints (default: { audio: true })

      Returns Promise<MediaStream>

      Promise that resolves with a MediaStream

      Example

      const stream = await MediaUtils.requestMicrophoneAccess();
      // Attach to audio element
      audioElement.srcObject = stream;
  • requestScreenAccess:function
    • Requests access to the user's screen (screen sharing).

      Parameters

      • constraints: MediaStreamConstraints = ...

        Media constraints (default: { video: true })

      Returns Promise<MediaStream>

      Promise that resolves with a MediaStream

      Example

      const stream = await MediaUtils.requestScreenAccess();
      // Attach to video element
      videoElement.srcObject = stream;
  • stopMediaStream:function
    • Stops all tracks in a MediaStream.

      Parameters

      • stream: MediaStream

        MediaStream to stop

      Returns void

      Example

      MediaUtils.stopMediaStream(stream);
      
  • createMediaRecorder:function
    • Creates a MediaRecorder instance for recording a MediaStream.

      Parameters

      • stream: MediaStream

        MediaStream to record

      • options: MediaRecorderOptions = {}

        MediaRecorder options

      Returns MediaRecorder

      MediaRecorder instance

      Example

      const recorder = MediaUtils.createMediaRecorder(stream);
      recorder.start();
  • recordMediaStream:function
    • Records a MediaStream to a Blob.

      Parameters

      • stream: MediaStream

        MediaStream to record

      • options: MediaRecorderOptions = {}

        MediaRecorder options

      Returns Promise<Blob>

      Promise that resolves with the recorded Blob

      Example

      const blob = await MediaUtils.recordMediaStream(stream);
      // Download the recording
      MediaUtils.downloadBlob(blob, 'recording.webm');
  • takeScreenshot:function
    • Takes a screenshot of a video element and returns it as a PNG Blob.

      Parameters

      • video: HTMLVideoElement

        Video element to capture

      Returns Promise<Blob>

      Promise that resolves with the screenshot as a Blob

      Throws

      If the canvas context cannot be obtained

      Example

      const screenshot = await MediaUtils.takeScreenshot(videoElement);
      MediaUtils.downloadBlob(screenshot, 'screenshot.png');
  • blobToBase64:function
    • Converts a Blob to a base64 string.

      Parameters

      • blob: Blob

        Blob to convert

      Returns Promise<string>

      Promise that resolves with the base64 string (without the data URL prefix)

      Example

      const base64 = await MediaUtils.blobToBase64(blob);
      console.log(base64);
  • base64ToBlob:function
    • Converts a base64 string to a Blob.

      Parameters

      • base64: string

        Base64 string to convert

      • type: string

        MIME type of the Blob

      Returns Blob

      The converted Blob

      Example

      const blob = MediaUtils.base64ToBlob(base64String, 'image/jpeg');
      
  • downloadBlob:function
    • Downloads a Blob as a file in the browser.

      Parameters

      • blob: Blob

        Blob to download

      • filename: string

        Name of the file

      Returns void

      Example

      MediaUtils.downloadBlob(blob, 'recording.webm');
      
  • getVideoDuration:function
    • Gets the duration of a video file in seconds.

      Parameters

      • file: File

        Video file

      Returns Promise<number>

      Promise that resolves with the duration in seconds

      Example

      const duration = await MediaUtils.getVideoDuration(videoFile);
      console.log(`Duration: ${duration} seconds`);
  • getVideoDimensions:function
    • Gets the dimensions of a video file.

      Parameters

      • file: File

        Video file

      Returns Promise<{
          width: number;
          height: number;
      }>

      Promise that resolves with the video dimensions

      Example

      const { width, height } = await MediaUtils.getVideoDimensions(videoFile);
      console.log(`Width: ${width}, Height: ${height}`);
  • getAudioDuration:function
    • Gets the duration of an audio file in seconds.

      Parameters

      • file: File

        Audio file

      Returns Promise<number>

      Promise that resolves with the duration in seconds

      Example

      const duration = await MediaUtils.getAudioDuration(audioFile);
      console.log(`Audio duration: ${duration} seconds`);
  • getImageDimensions:function
    • Gets the dimensions of an image file.

      Parameters

      • file: File

        Image file

      Returns Promise<{
          width: number;
          height: number;
      }>

      Promise that resolves with the image dimensions

      Example

      const { width, height } = await MediaUtils.getImageDimensions(imageFile);
      console.log(`Image: ${width}x${height}`);
  • resizeImage:function
    • Resizes an image file to fit within the specified maximum width and height.

      Parameters

      • file: File

        Image file to resize

      • maxWidth: number

        Maximum width

      • maxHeight: number

        Maximum height

      Returns Promise<Blob>

      Promise that resolves with the resized image as a Blob

      Example

      const resizedImage = await MediaUtils.resizeImage(imageFile, 800, 600);
      MediaUtils.downloadBlob(resizedImage, 'resized.jpg');
  • compressImage:function
    • Compresses an image file to reduce its size.

      Parameters

      • file: File

        Image file to compress

      • quality: number = 0.8

        Compression quality (0-1, default: 0.8)

      Returns Promise<Blob>

      Promise that resolves with the compressed image as a Blob

      Example

      const compressedImage = await MediaUtils.compressImage(imageFile, 0.7);
      MediaUtils.downloadBlob(compressedImage, 'compressed.jpg');