RemoteMediaModule
ClassAllows 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
Since Lens Scripting v173
Index
Properties
Methods
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
uniqueIdentifier
readonlyuniqueIdentifier:string
Since
Lens Scripting Version 176
Inherited from
Methods
getTypeName()
staticgetTypeName():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
getTypeName()
getTypeName():
string
Returns the name of this object's type.
Returns
string
Inherited from
isOfType()
isOfType(
type):boolean
Returns true if the object matches or derives from the passed in type.
Parameters
| Parameter | Type |
|---|---|
type | string |
Returns
boolean
Inherited from
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
| Parameter | Type |
|---|---|
other | ScriptObject |
Returns
boolean
Inherited from
loadResourceAsAudioTrackAsset()
loadResourceAsAudioTrackAsset(
resource,onSuccess,onFailure):void
Downloads the remote image resource from the DynamicResource object and loads the resource as AudioTrackAsset.
Parameters
| Parameter | Type |
|---|---|
resource | DynamicResource |
onSuccess | (audioTrackAsset) => void |
onFailure | (errorMessage) => void |
Returns
void
Since
Lens Scripting Version 179
loadResourceAsBytes()
loadResourceAsBytes(
resource,onSuccess,onFailure):void
Parameters
| Parameter | Type |
|---|---|
resource | DynamicResource |
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
| Parameter | Type |
|---|---|
resource | DynamicResource |
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
| Parameter | Type |
|---|---|
resource | DynamicResource |
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
| Parameter | Type |
|---|---|
resource | DynamicResource |
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
| Parameter | Type |
|---|---|
resource | DynamicResource |
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
| Parameter | Type |
|---|---|
resource | DynamicResource |
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
| Parameter | Type |
|---|---|
resource | DynamicResource |
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
| Parameter | Type |
|---|---|
resource | Texture |
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
| Parameter | Type |
|---|---|
texture | Texture |
onSuccess | (resource) => void |
onFailure | (errorMessage) => void |
Returns
void
Since
Lens Scripting Version 365