AssetManager class

Manage IModuleAsset objects that are used to move assets in and out of the module.

Signature:

export declare class AssetManager extends ExternalObject 

Extends: ExternalObject

Remarks

Provides methods for getting assets from the user's device, and creating new assets from within the module. Use Runtime.getAssetManager() to get an instance of this class.

Methods

MethodModifiersDescription
addToOutput(name, asset)Mark the given asset to be available to the Oooh platform after the module has finished running
createAudioAssetCollection()Create a new AudioAssetCollection that can be used to save multiple audio assets as a single output asset
createImageAssetCollection()Create a new ImageAssetCollection that can be used to save multiple images as a single output asset
createImageFromDataUri(dataUri)Creates a new image with the contents of the data URI. Used to store images generated from Canvas. For example, see Canvas.toDataURL
createReplayAssetCollection()Create a new ReplayDataAssetCollection that can be used to save multiple replay data recordings as a single output asset
createVideoAssetCollection()Create a new VideoAssetCollection that can be used to save multiple videos as a single output asset
getAudioFromFiles(title)Opens the native file picker, prompting the user to select an audio asset.
getImageFromGallery(title)Opens the native gallery picker, prompting the user to select an image asset.
getImageFromPath(path)Get an image file in your module distribution as an ImageAsset.
getImageFromPhoto(cameraType)Opens up the native photo-taking interface, allowing you to capture photos on demand for use in the module.
getInputAsset(name)Get an asset that has been passed from the framework into the module, available on startup.
getMediaFromGallery(mediaImportConfig)Opens the native gallery picker, prompting the user to select one or multiple image or video assets, as configured by the import config
getMetadata(video)Get metadata about a video asset
getSubmissions()When the PlayType is set to CreatorSubmissionProcessing this returns the data from audience plays that were selected by the creator before this module was run
getVideoFrame(video, frameTimeSeconds)Extract a frame of the video and returns it as an image asset
getVideoFromGallery(title, mediaImportConfig)Opens the native gallery picker, prompting the user to select a video asset.
getVideoFromPath(path)Get a video file in your module distribution as a VideoAsset.
removeAllOutputAssets()Remove all assets that have been previously added to the module output
removeFromOutput(name)Remove a previously added asset from the module output
saveImageToGallery(image)Saves an image to the user's photo album
shareImage(image)Exports an image asset for you to share outside the Oooh app using the OS sharing dialog.

AssetManager.addToOutput() method

Mark the given asset to be available to the Oooh platform after the module has finished running

Signature:

addToOutput(name: string, asset: IModuleAsset): void;

Parameters

ParameterTypeDescription
namestringThe identifier configured in the module setup
assetIModuleAssetThe asset to preserve

Returns:

void

AssetManager.createAudioAssetCollection() method

Create a new AudioAssetCollection that can be used to save multiple audio assets as a single output asset

Signature:

createAudioAssetCollection(): Promise<AudioAssetCollection>;

Returns:

Promise<AudioAssetCollection>

AssetManager.createImageAssetCollection() method

Create a new ImageAssetCollection that can be used to save multiple images as a single output asset

Signature:

createImageAssetCollection(): Promise<ImageAssetCollection>;

Returns:

Promise<ImageAssetCollection>

AssetManager.createImageFromDataUri() method

Creates a new image with the contents of the data URI. Used to store images generated from Canvas. For example, see Canvas.toDataURL

Signature:

createImageFromDataUri(dataUri: string): Promise<ImageAsset>;

Parameters

ParameterTypeDescription
dataUristringA Base64-encoded data URI string starting in "data:"

Returns:

Promise<ImageAsset>

A new image asset with the contents you provided

AssetManager.createReplayAssetCollection() method

Create a new ReplayDataAssetCollection that can be used to save multiple replay data recordings as a single output asset

Signature:

createReplayAssetCollection(): Promise<ReplayDataAssetCollection>;

Returns:

Promise<ReplayDataAssetCollection>

AssetManager.createVideoAssetCollection() method

Create a new VideoAssetCollection that can be used to save multiple videos as a single output asset

Signature:

createVideoAssetCollection(): Promise<VideoAssetCollection>;

Returns:

Promise<VideoAssetCollection>

AssetManager.getAudioFromFiles() method

Opens the native file picker, prompting the user to select an audio asset.

Signature:

getAudioFromFiles(title?: string): Promise<AudioAsset>;

Parameters

ParameterTypeDescription
titlestring(Optional) When supported by device, the title presented on the native gallery UI

Returns:

Promise<AudioAsset>

The chosen audio asset; if none is picked, the promise rejects

AssetManager.getImageFromGallery() method

Opens the native gallery picker, prompting the user to select an image asset.

Signature:

getImageFromGallery(title?: string): Promise<ImageAsset>;

Parameters

ParameterTypeDescription
titlestring(Optional) When supported by device, the title presented on the native gallery UI

Returns:

Promise<ImageAsset>

The chosen image asset; if none is picked, the promise rejects

AssetManager.getImageFromPath() method

Get an image file in your module distribution as an ImageAsset.

Signature:

getImageFromPath(path: string): Promise<ImageAsset>;

Parameters

ParameterTypeDescription
pathstringA path to an image file, relative to your module's index.html

Returns:

Promise<ImageAsset>

Remarks

Using a file outside your module path or at an arbitrary URL is not allowed.

Please ensure that the relative path to the asset does not differ between development and production builds to avoid errors!

Example

const maskImage = await assetManager.getImageFromPath('assets/mask.png'); // there should be a file in dist/assets/mask.png when your module is built

AssetManager.getImageFromPhoto() method

Opens up the native photo-taking interface, allowing you to capture photos on demand for use in the module.

Signature:

getImageFromPhoto(cameraType?: Enum<typeof CameraType>): Promise<ImageAsset>;

Parameters

ParameterTypeDescription
cameraTypeEnum<typeof CameraType>(Optional) Which camera to open with; the user may be able to switch this once presented. The default is to use the front facing camera.

Returns:

Promise<ImageAsset>

The photo taken as an image asset; if none is picked, the promise rejects

AssetManager.getInputAsset() method

Get an asset that has been passed from the framework into the module, available on startup.

Signature:

getInputAsset(name: string): IModuleAsset | undefined;

Parameters

ParameterTypeDescription
namestringThe asset identifier as setup in the module configuration

Returns:

IModuleAsset | undefined

An asset reference of the configured type

Remarks

You must use a fixed number of predetermined identifiers for your module. If you need dynamic collections, consider adding an asset of a collection type e.g. VideoAssetCollection with a fixed name.

AssetManager.getMediaFromGallery() method

Opens the native gallery picker, prompting the user to select one or multiple image or video assets, as configured by the import config

Signature:

getMediaFromGallery(mediaImportConfig?: MediaImportConfig): Promise<readonly IModuleAsset[]>;

Parameters

ParameterTypeDescription
mediaImportConfigMediaImportConfig(Optional) Import configuration including which types of media are allowed

Returns:

Promise<readonly IModuleAsset[]>

A list containing the selected assets; if none is picked, the promise rejects

Example

const assets = await o3h.Instance.getAssetManager().getMediaFromGallery({
    mediaTypes: ['image', 'video'],
    maxDurationSec: 30
});
for (const asset of assets) {
 if (asset instanceof o3h.ImageAsset) { ... }
}

AssetManager.getMetadata() method

Get metadata about a video asset

Signature:

getMetadata(video: VideoAsset): Promise<VideoMetadata>;

Parameters

ParameterTypeDescription
videoVideoAssetThe video asset

Returns:

Promise<VideoMetadata>

Remarks

This call can take more than half a second to run, so try to perform this operation behind the scenes

AssetManager.getSubmissions() method

When the PlayType is set to CreatorSubmissionProcessing this returns the data from audience plays that were selected by the creator before this module was run

Signature:

getSubmissions(): Promise<readonly Submission[]>;

Returns:

Promise<readonly Submission[]>

The list of submissions

AssetManager.getVideoFrame() method

Extract a frame of the video and returns it as an image asset

Signature:

getVideoFrame(video: VideoAsset, frameTimeSeconds: number): Promise<ImageAsset>;

Parameters

ParameterTypeDescription
videoVideoAssetA video asset
frameTimeSecondsnumberThe time in seconds to grab the frame from

Returns:

Promise<ImageAsset>

The frame of the video

Remarks

This call can take more than half a second to run, try to perform this operation behind the scenes

AssetManager.getVideoFromGallery() method

Opens the native gallery picker, prompting the user to select a video asset.

Signature:

getVideoFromGallery(title?: string, mediaImportConfig?: MediaImportConfig): Promise<VideoAsset>;

Parameters

ParameterTypeDescription
titlestring(Optional) When supported by device, the title presented on the native gallery UI
mediaImportConfigMediaImportConfig(Optional) Configuration for controlling the import settings

Returns:

Promise<VideoAsset>

The chosen video asset; if none is picked, the promise rejects

Remarks

This resolves only when selection is finished, not when the video is loaded. Refer to VideoComponent.prepareVideo() for loading the video after selection.

AssetManager.getVideoFromPath() method

Get a video file in your module distribution as a VideoAsset.

Signature:

getVideoFromPath(path: string): Promise<VideoAsset>;

Parameters

ParameterTypeDescription
pathstring

Returns:

Promise<VideoAsset>

Remarks

Using a file outside your module path or at an arbitrary URL is not allowed.

If you want to play a video from your module in a VideoComponent, you can do that without this method! Just pass a relative URL to VideoComponent.prepareVideo(), or initialize the component with it by setting it in VideoComponentConfig.url. Only use this method if you need the video as a VideoAsset, for example to submit as a module output asset.

AssetManager.removeAllOutputAssets() method

Remove all assets that have been previously added to the module output

Signature:

removeAllOutputAssets(): void;

Returns:

void

Remarks

Assets are deleted when they are removed from the output.

AssetManager.removeFromOutput() method

Remove a previously added asset from the module output

Signature:

removeFromOutput(name: string): void;

Parameters

ParameterTypeDescription
namestringThe identifier previously used to add the asset

Returns:

void

Remarks

Assets are deleted when they are removed from the output.

AssetManager.saveImageToGallery() method

Saves an image to the user's photo album

Signature:

saveImageToGallery(image: ImageAsset): Promise<void>;

Parameters

ParameterTypeDescription
imageImageAssetThe image asset to save

Returns:

Promise<void>

AssetManager.shareImage() method

Exports an image asset for you to share outside the Oooh app using the OS sharing dialog.

Signature:

shareImage(image: ImageAsset): Promise<void>;

Parameters

ParameterTypeDescription
imageImageAssetThe image asset to export and share

Returns:

Promise<void>

Remarks

Will decorate the image with some branding from Oooh and your module. These extra design elements can not be customized. If you need to change the look of an image, load it into a canvas and render it to a new image.

Example

await assetManager.shareImage(await assetManager.createImageFromDataUri(canvas.toDataURL('image/jpeg')));