Recording

Description

Supported Script Types:

  • Interface Scripts
  • Client Entity Scripts
  • Avatar Scripts
  • Assignment Client Scripts
The Recording API makes and plays back recordings of voice and avatar movements. Playback may be done on a user's avatar or an assignment client agent (see the Agent API).

Methods

Name Return Value Summary
getDefaultRecordingSaveDirectory string

Gets the default directory that recordings are saved in.

getPlayerUseAttachments boolean

Not used.

Deprecated: This method is deprecated and will be removed.

getPlayerUseDisplayName boolean

Gets whether recording playback will use the display name that the recording was made with.

getPlayerUseHeadModel boolean

Not used.

Deprecated: This method is deprecated and will be removed.

getPlayerUseSkeletonModel boolean

Gets whether recording playback will use the avatar model that the recording was made with.

getPlayFromCurrentLocation boolean

Gets whether recordings are played at the current avatar location or the recorded location.

isPaused boolean

Gets whether recording playback is currently paused.

isPlaying boolean

Gets whether a recording is currently playing.

isRecording boolean

Gets whether a recording is currently being made.

loadLastRecording None

Loads the most recently made recording and plays it back on your avatar.

loadRecording None

Loads a recording so that it is ready for playing.

pausePlayer None

Pauses playback of the recording currently playing. Use startPlaying to resume playback or stopPlaying to stop playback.

playerElapsed number

Gets the current playback time in the loaded recording, in seconds.

playerLength number

Gets the length of the loaded recording, in seconds.

recorderElapsed number

Gets the duration of the recording currently being made or recently made, in seconds.

saveRecording None

Saves the most recently made recording to a file.

saveRecordingToAsset boolean

Saves the most recently made recording to the domain's asset server.

setPlayerAudioOffset None

Not implemented: This method is not implemented yet.

setPlayerLoop None

Sets whether playback should repeat in a loop.

setPlayerTime None

Sets the current playback time in the loaded recording.

setPlayerUseAttachments None

Not used.

Deprecated: This method is deprecated and will be removed.

setPlayerUseDisplayName None

Sets whether recording playback will use the display name that the recording was made with.

setPlayerUseHeadModel None

Not used.

Deprecated: This method is deprecated and will be removed.

setPlayerUseSkeletonModel None

Sets whether recording playback will use the avatar model that the recording was made with.

setPlayerVolume None

Sets the playback audio volume.

setPlayFromCurrentLocation None

Sets whether recordings are played at the current avatar location or the recorded location.

startPlaying None

Starts playing the recording currently loaded or paused.

startRecording None

Starts making a recording.

stopPlaying None

Stops playing the recording currently playing or paused.

stopRecording None

Stops making a recording. The recording may be saved using saveRecording or saveRecordingToAsset, or immediately played back with loadLastRecording.

Type Definitions

loadRecordingCallback( success, url )
Type: function

Called when a Recording.loadRecording call is complete.

Parameters

Name Type Description
success boolean

true if the recording has successfully been loaded, false if it hasn't.

url string

The URL of the recording that was requested to be loaded.

saveRecordingToAssetCallback( url )
Type: function

Called when a Recording.saveRecordingToAsset call is complete.

Parameters

Name Type Description
url string

The URL of the recording stored in the asset server if successful, "" if unsuccessful. The URL has atp: as the scheme and the SHA256 hash as the filename (with no extension).

Method Details

(static) getDefaultRecordingSaveDirectory( ) → {string}
Returns: The default recording save directory.

Gets the default directory that recordings are saved in.

Example

Report the default save directory.

print("Default save directory: " + Recording.getDefaultRecordingSaveDirectory());
(static) getPlayerUseAttachments( ) → {boolean}
Returns: Use attachments.

Not used.

Deprecated: This method is deprecated and will be removed.

(static) getPlayerUseDisplayName( ) → {boolean}
Returns: true if recording playback will use the display name that the recording was made with, false if playback will keep the current display name.

Gets whether recording playback will use the display name that the recording was made with.

(static) getPlayerUseHeadModel( ) → {boolean}
Returns: Use head model.

Not used.

Deprecated: This method is deprecated and will be removed.

(static) getPlayerUseSkeletonModel( ) → {boolean}
Returns: true if recording playback will use the avatar model that the recording was made with, false if playback will use the current avatar model.

Gets whether recording playback will use the avatar model that the recording was made with.

(static) getPlayFromCurrentLocation( ) → {boolean}
Returns: true if recordings are played at the current avatar location, false if played at the recorded location.

Gets whether recordings are played at the current avatar location or the recorded location.

(static) isPaused( ) → {boolean}
Returns: true if recording playback is currently paused, false if it isn't.

Gets whether recording playback is currently paused.

(static) isPlaying( ) → {boolean}
Returns: true if a recording is being played, false if one isn't.

Gets whether a recording is currently playing.

(static) isRecording( ) → {boolean}
Returns: true if a recording is currently being made, false if one isn't.

Gets whether a recording is currently being made.

(static) loadLastRecording( )

Loads the most recently made recording and plays it back on your avatar.

Example

Make a 5 second recording and immediately play it back on your avatar.

Recording.startRecording();

Script.setTimeout(function () {
    Recording.stopRecording();
    Recording.loadLastRecording();
}, 5000);
     
(static) loadRecording( url, callbackopt )

Loads a recording so that it is ready for playing.

Parameters

Name Type Attributes Default Value Description
url string

The ATP, HTTP, or file system URL of the recording to load.

callback Recording~loadRecordingCallback <optional>
null

The function to call upon completion.

Example

Load and play back a recording from the asset server.

var assetPath = Window.browseAssets();
print("Asset path: " + assetPath);

if (assetPath.slice(-4) === ".hfr") {
    Recording.loadRecording("atp:" + assetPath, function (success, url) {
        if (!success) {
            print("Error loading recording.");
            return;
        }
        Recording.startPlaying();
    });
}
(static) pausePlayer( )

Pauses playback of the recording currently playing. Use startPlaying to resume playback or stopPlaying to stop playback.

(static) playerElapsed( ) → {number}
Returns: The current playback time in the loaded recording, in seconds.

Gets the current playback time in the loaded recording, in seconds.

(static) playerLength( ) → {number}
Returns: The length of the recording currently loaded, in seconds

Gets the length of the loaded recording, in seconds.

(static) recorderElapsed( ) → {number}
Returns: The duration of the recording currently being made or recently made, in seconds.

Gets the duration of the recording currently being made or recently made, in seconds.

(static) saveRecording( filename )

Saves the most recently made recording to a file.

Parameters

Name Type Description
filename string

The path and name of the file to save the recording to.

Example

Save a 5 second recording to a file.

Recording.startRecording();

Script.setTimeout(function () {
    Recording.stopRecording();
    var filename = (new Date()).toISOString();  // yyyy-mm-ddThh:mm:ss.sssZ
    filename = filename.slice(0, -5).replace(/:/g, "").replace("T", "-") 
        + ".hfr";  // yyyymmmdd-hhmmss.hfr
    filename = Recording.getDefaultRecordingSaveDirectory() + filename;
    Recording.saveRecording(filename);
    print("Saved recording: " + filename);
}, 5000);
(static) saveRecordingToAsset( callback ) → {boolean}
Returns: true if the recording is successfully being saved, false if not.

Saves the most recently made recording to the domain's asset server.

Parameters

Name Type Description
callback Recording~saveRecordingToAssetCallback

The function to call upon completion.

Example

Save a 5 second recording to the asset server.

function onSavedRecordingToAsset(url) {
    if (url === "") {
        print("Couldn't save recording.");
        return;
    }

    print("Saved recording: " + url);  // atp:SHA256

    var filename = (new Date()).toISOString();  // yyyy-mm-ddThh:mm:ss.sssZ
    filename = filename.slice(0, -5).replace(/:/g, "").replace("T", "-")
        + ".hfr";  // yyyymmmdd-hhmmss.hfr
    var hash = url.slice(4);  // Remove leading "atp:" from url.
    mappingPath = "/recordings/" + filename;
    Assets.setMapping(mappingPath, hash, function (error) {
        if (error) {
            print("Mapping error: " + error);
        }
    });
    print("Mapped recording: " + mappingPath);  // /recordings/filename
}

Recording.startRecording();

Script.setTimeout(function () {
    Recording.stopRecording();
    var success = Recording.saveRecordingToAsset(onSavedRecordingToAsset);
    if (!success) {
        print("Couldn't save recording.");
    }
}, 5000);
(static) setPlayerAudioOffset( audioOffset )

Not implemented: This method is not implemented yet.

Parameters

Name Type Description
audioOffset number

Audio offset.

(static) setPlayerLoop( loop )

Sets whether playback should repeat in a loop.

Parameters

Name Type Description
loop boolean

true if playback should repeat, false if it shouldn't.

(static) setPlayerTime( time )

Sets the current playback time in the loaded recording.

Parameters

Name Type Description
time number

The current playback time, in seconds.

(static) setPlayerUseAttachments( useAttachments )

Not used.

Deprecated: This method is deprecated and will be removed.

Parameters

Name Type Description
useAttachments boolean

Use attachments.

(static) setPlayerUseDisplayName( useDisplayName )

Sets whether recording playback will use the display name that the recording was made with.

Parameters

Name Type Description
useDisplayName boolean

true to have recording playback use the display name that the recording was made with, false to have recording playback keep the current display name.

(static) setPlayerUseHeadModel( useHeadModel )

Not used.

Deprecated: This method is deprecated and will be removed.

Parameters

Name Type Description
useHeadModel boolean

Use head model.

(static) setPlayerUseSkeletonModel( useSkeletonModel )

Sets whether recording playback will use the avatar model that the recording was made with.

Parameters

Name Type Description
useSkeletonModel boolean

true to have recording playback use the avatar model that the recording was made with, false to have playback use the current avatar model.

(static) setPlayerVolume( volume )

Sets the playback audio volume.

Parameters

Name Type Description
volume number

The playback audio volume, range 0.01.0.

(static) setPlayFromCurrentLocation( playFromCurrentLocation )

Sets whether recordings are played at the current avatar location or the recorded location.

Parameters

Name Type Description
playFromCurrentLocation boolean

true to play recordings at the current avatar location, false to play recordings at the recorded location.

(static) startPlaying( )

Starts playing the recording currently loaded or paused.

(static) startRecording( )

Starts making a recording.

(static) stopPlaying( )

Stops playing the recording currently playing or paused.

(static) stopRecording( )

Stops making a recording. The recording may be saved using saveRecording or saveRecordingToAsset, or immediately played back with loadLastRecording.