SoundCache

Description

The SoundCache API manages sound cache resources.

Supported Script Types: Interface Scripts • Client Entity Scripts • Avatar Scripts • Server Entity Scripts • Assignment Client Scripts

Properties

Name Type Summary
numTotal number Total number of total resources. Read-only.
numCached number Total number of cached resource. Read-only.
sizeTotal number Size in bytes of all resources. Read-only.
sizeCached number Size in bytes of all cached resources. Read-only.

Methods

Name Return Value Summary
getResourceList Array.<string> Gets the URLs of all resources in the cache.
getSound SoundObject Loads the content of an audio file into a SoundObject, ready for playback by Audio.playSound.
prefetch ResourceObject Prefetches a resource.
updateTotalSize None

Deprecated: This function is deprecated and will be removed.

Signals

Name Summary
dirty Triggered when the cache content has changed.

Method Details

(static) getResourceList( ) → {Array.<string>}
Returns: The URLs of all resources in the cache.

Gets the URLs of all resources in the cache.

Example

Report cached resources.

// Replace AnimationCache with ModelCache, SoundCache, or TextureCache as appropriate.

var cachedResources = AnimationCache.getResourceList();
print("Cached resources: " + JSON.stringify(cachedResources));
(static) getSound( url ) → {SoundObject}
Returns: The sound ready for playback.

Loads the content of an audio file into a SoundObject, ready for playback by Audio.playSound.

Parameters

Name Type Description
url string The URL of the audio file to load — Web, ATP, or file. See SoundObject for supported formats.
(static) prefetch( url ) → {ResourceObject}
Returns: A resource object.

Prefetches a resource.

Parameters

Name Type Description
url string The URL of the resource to prefetch.
Example

Prefetch a resource and wait until it has loaded.

// Replace AnimationCache with ModelCache, SoundCache, or TextureCache as appropriate.
// TextureCache has its own version of this function.

var resourceURL = "https://s3-us-west-1.amazonaws.com/hifi-content/clement/production/animations/sitting_idle.fbx";
var resourceObject = AnimationCache.prefetch(resourceURL);

function checkIfResourceLoaded(state) {
    if (state === Resource.State.FINISHED) {
        print("Resource loaded and ready.");
    } else if (state === Resource.State.FAILED) {
        print("Resource not loaded.");
    }
}

// Resource may have already been loaded.
print("Resource state: " + resourceObject.state);
checkIfResourceLoaded(resourceObject.state);

// Resource may still be loading.
resourceObject.stateChanged.connect(function (state) {
    print("Resource state changed to: " + state);
    checkIfResourceLoaded(state);
});
(static) updateTotalSize( deltaSize )

Deprecated: This function is deprecated and will be removed.

Parameters

Name Type Description
deltaSize number Delta size.

Signal Details

dirty( )
Returns: Signal

Triggered when the cache content has changed.