Preparing search index...

    Static utility class for loading various types of media from URLs. All methods are asynchronous and return Promises.

    This module requires:

    • LensStudio:Network - For HTTP requests
    • LensStudio:Ui - For Pixmap and Movie types
    • IStorage from FileSystem module - For file operations (Pixmap/Movie only)

    Option 1: Initialize storage once (recommended for multiple media loads)

    import { RemoteMediaModule } from 'LensStudio:RemoteMediaModule.js';
    import { ScopedStorage } from 'LensStudio:ScopedStorage.js';

    // Initialize once at startup
    RemoteMediaModule.initializeStorage(new ScopedStorage());

    // Then load media without passing storage each time
    const config = await RemoteMediaModule.loadAsJson('https://api.example.com/config.json');
    const pixmap = await RemoteMediaModule.loadAsPixmap(config.imageUrl);
    const movie = await RemoteMediaModule.loadAsMovie('https://example.com/video.mp4');

    Option 2: Pass storage per call

    const storage = new ScopedStorage();
    const pixmap = await RemoteMediaModule.loadAsPixmap('https://example.com/image.png', storage);
    Index

    Constructors

    Properties

    createRequest: any

    Creates an HTTP GET request for the specified URL.

    The URL to request

    Configured HTTP request object

    getFilename: any

    Extracts the filename from a URL. Removes query parameters and fragments.

    The URL to extract the filename from

    The filename (everything after the last /)

    // Returns "image.png"
    getFilename('https://example.com/path/image.png?size=large#preview');
    storage?: any

    Methods

    • Initializes the storage for the RemoteMediaModule. Call this once to set a default storage for all media loading operations. After initialization, storage parameter becomes optional for loadAsPixmap and loadAsMovie.

      Parameters

      • storage: IStorage

        The storage instance to use as default for media loading

      Returns void

      import { RemoteMediaModule } from 'LensStudio:RemoteMediaModule.js';
      import { ScopedStorage } from 'LensStudio:ScopedStorage.js';

      // Initialize once at startup
      RemoteMediaModule.initializeStorage(new ScopedStorage());

      // Then use without passing storage
      const pixmap = await RemoteMediaModule.loadAsPixmap('https://example.com/image.png');
    • Loads content from a URL as a byte array.

      Parameters

      • url: string

        The URL to load from

      Returns Promise<Uint8Array>

      Promise resolving to the response body as a Uint8Array

      Rejects with the HTTP status code if the request fails

      const bytes = await RemoteMediaModule.loadAsBytes('https://example.com/file.bin');
      
    • Loads and parses JSON content from a URL.

      Parameters

      • url: string

        The URL to load from

      Returns Promise<object>

      Promise resolving to the parsed JSON object

      Rejects with the HTTP status code if the request fails, or parsing error if JSON is invalid

      const data = await RemoteMediaModule.loadAsJson('https://api.example.com/data.json');
      console.log(data.someProperty);
    • Loads a video from a URL and creates a Movie. The video is downloaded, saved to storage, and then loaded as a Movie.

      Parameters

      • url: string

        The URL of the video

      • Optionalstorage: IStorage

        Optional storage instance. If not provided, uses the storage from initializeStorage()

      Returns Promise<Movie>

      Promise resolving to a Movie object

      Rejects with the HTTP status code if the request fails, or Error if no storage is available

      // Option 1: Pass storage directly
      const storage = new ScopedStorage();
      const movie = await RemoteMediaModule.loadAsMovie('https://example.com/video.mp4', storage);

      // Option 2: Use initialized storage
      RemoteMediaModule.initializeStorage(new ScopedStorage());
      const movie = await RemoteMediaModule.loadAsMovie('https://example.com/video.mp4');
    • Loads an image from a URL and creates a Pixmap. The image is downloaded, saved to storage, and then loaded as a Pixmap.

      Parameters

      • url: string

        The URL of the image

      • Optionalstorage: IStorage

        Optional storage instance. If not provided, uses the storage from initializeStorage()

      Returns Promise<Pixmap>

      Promise resolving to a Pixmap object

      Rejects with the HTTP status code if the request fails, or Error if no storage is available

      // Option 1: Pass storage directly
      const storage = new ScopedStorage();
      const pixmap = await RemoteMediaModule.loadAsPixmap('https://example.com/image.png', storage);

      // Option 2: Use initialized storage
      RemoteMediaModule.initializeStorage(new ScopedStorage());
      const pixmap = await RemoteMediaModule.loadAsPixmap('https://example.com/image.png');
    • Loads content from a URL as a string.

      Parameters

      • url: string

        The URL to load from

      Returns Promise<string>

      Promise resolving to the response body as a string

      Rejects with the HTTP status code if the request fails

      const text = await RemoteMediaModule.loadAsString('https://example.com/data.txt');
      console.log(text);