VideoTextureProvider
ClassControls a video texture resource.
- Available on all platforms
Controls a video texture resource. Can be accessed through Texture.control.
Index
Properties
Methods
Example
// Plays a video texture
//@input Asset.Texture movie
var loops = 100;
var provider = script.movie.control;
provider.play(loops);
//@input Asset.Texture movie
var provider = script.movie.control;
var seekTime = 5.0; // Seek to 5 seconds into the video
if (provider) {
// The video automatically plays from 5 seconds
provider.seek(seekTime);
print("Video resumed from " + seekTime + " seconds");
} else {
print("Video control not available");
}
Extends
Properties
autoplay
readonlyautoplay:boolean
Returns true if autoplay is enabled for this video texture.
Since
Lens Scripting Version 352
currentPlayCount
readonlycurrentPlayCount:number
Returns the number of played cycles.
currentTime
readonlycurrentTime:number
Returns the current time in seconds, or zero if accessed during playback being in unprepared state.
Since
Lens Scripting Version 160
duration
readonlyduration:number
Returns the duration of playback range in seconds, or zero if accessed while playback is in an unprepared state.
Since
Lens Scripting Version 160
isPlaybackReady
readonlyisPlaybackReady:boolean
Returns true if video file has been loaded and is ready for decoding and false otherwise.
lastFrameTime
readonlylastFrameTime:number
Returns the time of the last acquired texture in seconds, or zero if accessed during playback being in unprepared state.
Since
Lens Scripting Version 160
mixToSnap
mixToSnap:
boolean
When true, the video's own audio track is recorded directly into the Snap, overriding the microphone input. Use this to capture an MP4's audio (or to mute the microphone) without attaching an AudioComponent. This is an authoring setting applied when the video is loaded; changing it dynamically during recording is not supported.
Since
Lens Scripting Version 368
Default Value
false
Example
// Record the video's audio into the Snap instead of the microphone
//@input Asset.Texture movie
var provider = script.movie.control;
provider.mixToSnap = true;
onPlaybackDone
readonlyonPlaybackDone:event0<void>
The event for being reported about playback finished. When this event is triggered, lens developers can evict this texture from material slots to avoid disrupting user's experience.
Since
Lens Scripting Version 160
onPlaybackReady
readonlyonPlaybackReady:event0<void>
The event for being reported about playback start. When this event is triggered, lens developers can set video texture to material slots and see actual video frames.
Since
Lens Scripting Version 160
playbackRate
playbackRate:
number
The playback rate of the video. This value is applied when the video is loaded via VideoTextureProvider.load. To change the playback rate after loading, call VideoTextureProvider.unload first, set the new rate, then call VideoTextureProvider.load again.
Since
Lens Scripting Version 186
Default Value
1
relativeEndTime
relativeEndTime:
number
The relative end time of playback in the range [0, 1], where 0 is the beginning and 1 is the end of the video. This value is applied when the video is loaded via VideoTextureProvider.load. To change after loading, call VideoTextureProvider.unload first, set the new value, then call VideoTextureProvider.load again.
Since
Lens Scripting Version 160
Default Value
1
relativeStartTime
relativeStartTime:
number
The relative start time of playback in the range [0, 1], where 0 is the beginning and 1 is the end of the video. This value is applied when the video is loaded via VideoTextureProvider.load. To change after loading, call VideoTextureProvider.unload first, set the new value, then call VideoTextureProvider.load again.
Since
Lens Scripting Version 160
Default Value
0
status
readonlystatus:VideoStatus
A read-only property that returns the status of provider. Suggested as a substitution for the existing getStatus()
Since
Lens Scripting Version 160
totalDuration
readonlytotalDuration:number
Returns the duration of loaded video file in seconds, or zero if accessed during playback being in unprepared state.
Since
Lens Scripting Version 160
volume
volume:
number
The audio volume of the video resource, normalized from 0 to 1. Can be changed dynamically during playback.
Default Value
1
Methods
ensureLoaded()
ensureLoaded():
Promise<void>
Returns a Promise that resolves once this Provider has finished loading its resource.
Returns
Promise<void>
Remarks
If the Provider is already loaded when ensureLoaded() is called, the returned Promise
resolves immediately. Otherwise it resolves once loading completes.
Completion is determined by the Provider's load status (see Provider.getLoadStatus). Some Providers only become loaded once supporting runtime data is available — for example, a Provider whose resource depends on tracking will not report loaded until the relevant tracking data has arrived — so the returned Promise stays pending until that data is produced.
This method is useful when Lens script needs to await a Provider before reading its data — for example, waiting for a remote-asset Provider to finish downloading before sampling it.
Since
Lens Scripting Version 370
Example
Fetch a Texture at runtime via RemoteMediaModule and wait for its Provider to finish loading before using it:
const internetModule = require("LensStudio:InternetModule");
const remoteMediaModule = require("LensStudio:RemoteMediaModule");
function loadImageTexture(url) {
const resource = internetModule.makeResourceFromUrl(url);
return new Promise((resolve, reject) => {
remoteMediaModule.loadResourceAsImageTexture(resource, resolve, reject);
});
}
const texture = await loadImageTexture("https://example.com/image.png");
// Wait until the fetched Texture's Provider has finished loading before using it.
await texture.control.ensureLoaded();
print("Texture ready, loadStatus: " + texture.control.getLoadStatus());
Inherited from
getAspect()
getAspect():
number
Returns the texture's aspect ratio, which is calculated as width / height.
Returns
number
Inherited from
getHeight()
getHeight():
number
Returns the height of the texture in pixels.
Returns
number
Inherited from
getLoadStatus()
getLoadStatus():
LoadStatus
Returns
Inherited from
getTypeName()
staticgetTypeName():TypeName<VideoTextureProvider>
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<VideoTextureProvider>
Overrides
getTypeName()
getTypeName():
string
Returns the name of this object's type.
Returns
string
Inherited from
getWidth()
getWidth():
number
Returns the width of the texture in pixels.
Returns
number
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
load()
load(
loopOnLoad):void
Loads the video stream and stops on the first frame. Results in the video being in the Stopped state, ready to play. loopOnLoad If true, prepares the video for looped playback. If false, prepares for single playback. This may affect which decoder is used on some platforms.
Parameters
| Parameter | Type |
|---|---|
loopOnLoad | boolean |
Returns
void
Since
Lens Scripting Version 349
Example
// Load video and stop on first frame
var videoControl = videoTexture.control;
videoControl.load(false); // Load for single playback
// Wait for video to be ready
videoControl.onPlaybackReady.add(function() {
print("Video ready at first frame, Status=Stopped");
// Now you can play it
videoControl.play(1);
});
// Load video prepared for looping
var videoControl = videoTexture.control;
videoControl.load(true); // Load prepared for looping
videoControl.onPlaybackReady.add(function() {
videoControl.play(-1); // Play infinitely
});
pause()
pause():
void
Pauses the video playback.
Returns
void
play()
play(
playCount):void
Plays the video playCount times. If playCount is less than 0, it loops infinitely.
Parameters
| Parameter | Type |
|---|---|
playCount | number |
Returns
void
resume()
resume():
void
Resumes the video playback.
Returns
void
seek()
seek(
value):boolean
Sets the current playback time to the specified time in seconds.
Parameters
| Parameter | Type |
|---|---|
value | number |
Returns
boolean
Since
Lens Scripting Version 160
stop()
stop():
void
Stops the video playback and resets position to the beginning. Resources remain loaded. To resume playback, call play() again.
Returns
void
Example
// Stop video and reset to beginning
var videoControl = videoTexture.control;
videoControl.play(1);
// ... later, stop the video
videoControl.stop();
// Video is now stopped at time 0 (status is VideoStatus.Stopped)
// To play again, call play()
videoControl.play(1);
unload()
unload():
void
Unloads the video and releases all resources.
Returns
void
Since
Lens Scripting Version 349
Example
// Unload video to free resources
var videoControl = videoTexture.control;
videoControl.unload();
// Video status is now VideoStatus.Unloaded