Skip to main content

RemoteMediaModule

Class

Allows the Lens to download and integrate remote media content such as 3D GLTF assets, images, audio tracks, and video textures into Lenses.

  • Available on all platforms
Platform details: Snapchat, SPECS, Camera Kit Web, Camera Kit Mobile fully supported.

Platform details

  • Snapchat — Fully supported.

  • SPECS — Fully supported.

  • Camera Kit Web — Fully supported.

  • Camera Kit Mobile — Fully supported.

Since Lens Scripting v173

Index

Example

// @input Asset.BitmojiModule bitmojiModule
// @input Asset.RemoteMediaModule remoteMediaModule
// @input Asset.Material pbrMaterialHolder

script.bitmojiModule.requestBitmoji3DResource(
function (bitmoji3DResource) {
script.remoteMediaModule.loadResourceAsGltfAsset(
bitmoji3DResource,
onDownloaded,
onFail
)
}
)

function onDownloaded (gltfAsset){
var root = scene.createSceneObject("BitmojiAvatar");
var avatar = gltfAsset.tryInstantiate(root, script.pbrMaterialHolder);
}

function onFail (e){
print(e);
}

Extends

Properties

name

name: string

The name of the Asset in Lens Studio.

Default Value

""

Inherited from

Asset.name


uniqueIdentifier

readonly uniqueIdentifier: string

Since

Lens Scripting Version 176

Inherited from

Asset.uniqueIdentifier

Methods

getTypeName()

static getTypeName(): TypeName<RemoteMediaModule>

Returns the fully-qualified JavaScript type name for this class (for example, "Component.Camera"). This is a static accessor (no instance required) and returns the same value as the instance getTypeName().

Returns

TypeName<RemoteMediaModule>

Since

Lens Scripting Version 173

Overrides

Asset.getTypeName


getTypeName()

getTypeName(): string

Returns the name of this object's type.

Returns

string

Inherited from

Asset.getTypeName


isOfType()

isOfType(type): boolean

Returns true if the object matches or derives from the passed in type.

Parameters

ParameterType
typestring

Returns

boolean

Inherited from

Asset.isOfType


isSame()

isSame(other): boolean

Returns true if this object is the same as other. Useful for checking if two references point to the same thing.

Parameters

ParameterType
otherScriptObject

Returns

boolean

Inherited from

Asset.isSame


loadResourceAsAudioTrackAsset()

loadResourceAsAudioTrackAsset(resource, onSuccess, onFailure): void

Downloads the remote image resource from the DynamicResource object and loads the resource as AudioTrackAsset.

Parameters

ParameterType
resourceDynamicResource
onSuccess(audioTrackAsset) => void
onFailure(errorMessage) => void

Returns

void

Since

Lens Scripting Version 179


loadResourceAsBytes()

loadResourceAsBytes(resource, onSuccess, onFailure): void

Parameters

ParameterType
resourceDynamicResource
onSuccess(bytes) => void
onFailure(errorMessage) => void

Returns

void

Since

Lens Scripting Version 320


loadResourceAsGaussianSplattingAsset()

loadResourceAsGaussianSplattingAsset(resource, onSuccess, onFailure): void

Download the file from the DynamicResource object and loads the resource as a GaussianSplattingAsset. Supported file formats: .ply, .gs, .gsaf, .gfrosting

Parameters

ParameterType
resourceDynamicResource
onSuccess(gaussianSplattingAsset) => void
onFailure(errorMessage) => void

Returns

void

Since

Lens Scripting Version 320

Example

// @input Asset.RemoteMediaModule mediaModule
// @input string url

let gsVisual = script.getSceneObject().getComponent(GaussianSplattingVisual.getTypeName())
function success(gsa) { gsVisual.asset = gsa }
function fail(msg) { print('Error: ' + msg) }
const resource = DynamicResource.createWithResourceId(script.url)
script.mediaModule.loadResourceAsGaussianSplattingAsset(resource, success, fail)

loadResourceAsGltfAsset()

loadResourceAsGltfAsset(resource, onSuccess, onFailure): void

Downloads a remote 3D GLTF file given a DynamicResource.

Parameters

ParameterType
resourceDynamicResource
onSuccess(glTFAsset) => void
onFailure(errorMessage) => void

Returns

void

Since

Lens Scripting Version 173


loadResourceAsImageTexture()

loadResourceAsImageTexture(resource, onSuccess, onFailure): void

Downloads the remote image resource from the DynamicResource object and loads the resource as an Image Texture.

Parameters

ParameterType
resourceDynamicResource
onSuccess(texture) => void
onFailure(errorMessage) => void

Returns

void

Since

Lens Scripting Version 179


loadResourceAsRuntimeBundle()

loadResourceAsRuntimeBundle(resource, onSuccess, onFailure): void

Downloads the remote asset resource from the DynamicResource object and loads the resource as an Asset.

If the runtime bundle uses any permission-requiring modules (e.g. CameraModule), those permissions must be declared in the original Lens that loads the bundle. Use require statements in the parent Lens script to declare them; the runtime bundle itself cannot request permissions on its own. Omitting the required require calls will not cause an error in Lens Studio but will be blocked by permission checks at runtime on device.

Parameters

ParameterType
resourceDynamicResource
onSuccess(asset) => void
onFailure(errorMessage) => void

Returns

void

Since

Lens Scripting Version 328

Example

// Declare permissions for any modules used inside the runtime bundle:
require('LensStudio:CameraModule');
require('LensStudio:SpectaclesMobileKitModule');
require('LensStudio:SupabaseModule');
// ...

const internetModule = require('LensStudio:InternetModule');
const remoteMediaModule = require('LensStudio:RemoteMediaModule');

var response = await internetModule.fetch("runtimeBundleUrl");
var blob = await response.blob();
var dynamicResource = DynamicResource.createWithBuffer(await blob.bytes());
remoteMediaModule.loadResourceAsRuntimeBundle(
dynamicResource,
function(asset) { print('Loaded: ' + asset); },
function(err) { print('Error: ' + err); }
);

loadResourceAsString()

loadResourceAsString(resource, onSuccess, onFailure): void

Parameters

ParameterType
resourceDynamicResource
onSuccess(string) => void
onFailure(errorMessage) => void

Returns

void

Since

Lens Scripting Version 320


loadResourceAsVideoTexture()

loadResourceAsVideoTexture(resource, onSuccess, onFailure): void

Downloads the remote image resource from the DynamicResource object and loads the resource as a VideoTextureProvider.

Parameters

ParameterType
resourceDynamicResource
onSuccess(texture) => void
onFailure(errorMessage) => void

Returns

void

Since

Lens Scripting Version 179


uploadImage()

uploadImage(resource, onSuccess, onFailure, uploadOptions?): void

Uploads a Texture as an image and returns a DynamicResource on success. Use ImageUploadOptions to configure the compression method, quality, and alpha channel inclusion.

Parameters

ParameterType
resourceTexture
onSuccess(resource) => void
onFailure(errorMessage) => void
uploadOptions?ImageUploadOptions

Returns

void

Since

Lens Scripting Version 353


uploadVideo()

uploadVideo(texture, onSuccess, onFailure): void

Uploads a video from a Texture containing a VideoTextureProvider to the remote server and returns a DynamicResource on success. The Texture must have been created from a video file (e.g., from VideoRecorder.stopRecording()).

Parameters

ParameterType
textureTexture
onSuccess(resource) => void
onFailure(errorMessage) => void

Returns

void

Since

Lens Scripting Version 365