Manages recording and playing back of stand-alone archives. A stand-alone archive is
a video that is recorded independent of an OpenTok session. (In contrast, the Session.startRecording()
and Stream.startRecording() methods record streams in an OpenTok session.)
Use the RecorderManager class to create Recorder and Player objects. Use the Recorder class to record a video archive.
Once you have recorded and saved an archive, you can play the archive back in a stand-alone player,
using the Player class. Or you can play it back in an OpenTok session (using the Session.loadArchive()
and Archive.startPlayback() methods). If you play an archive back in an OpenTok session,
all clients connected to the session can view the archive playback.
Note: The OpenTok archiving API also lets your record archives of audio-video streams in an OpenTok session, as well as stand-alone archives. See the documentation for the Session.createArchive() method.
See
The RecorderManager object has the following methods.
| Method | Description |
|---|---|
| displayPlayer(archiveId:String, token:String [, replaceElementId:String, properties:Object]):Player | Displays a player (for playing back individual archives). |
| displayRecorder(token:String [, replaceElementId:String, properties:Object]):Recorder | Displays a recorder (for recording individual archives). |
| removePlayer(player:Player) | Removes the specified player from the HTML DOM. |
| removeRecorder(recorder:Recorder) | Removes the specified recorder from the HTML DOM. |
Displays a player for playing back stand-alone archives.
The method returns a Player object. The player is displayed in the HTML page.
Parameters
archiveId (String) The archive ID of the archive that you initially want to load in the Player.
token (String) An OpenTok token string. The token must have been
assigned the role of moderator. Generate OpenTok tokens using the createToken()
method of the OpenTok server-side library or the Dashboard page.
replacementElementId (String) The ID of the DOM element that
the recorder will replace. This value is optional. If you do not specify a replacement
element ID, the method appends the recorder as a child of the body element,
centered in the page.
properties (Object) This object can have the following properties (each of which is optional):
false.style object includes the following
properties:"auto" (controls are displayed when the stream is first displayed
and when the user mouses over the display), "off" (controls are not displayed),
and "on" (controls are displayed).style property to control
the display of the Pause button, and the Play button.wmode values for
the object and embed tags for a SWF file: "opaque",
"transparent" (the default), or "window". (For more information, see
Flash OBJECT and EMBED tag
attributes (at adobe.com).
To remove the player from the page, call the removePlayer() method.
Returns
Player The Player object.
See
Displays a recorder for recording an archive.
The displayRecorder() method returns a Recorder object. The recorder is displayed
in the HTML page.
Parameters
token (String) An OpenTok token string. The token must have been
assigned the role of moderator. Generate OpenTok tokens using the createToken()
method of the OpenTok server-side library or the Dashboard page.
replacementElementId (String) The ID of the DOM element that
the recorder will replace. This value is optional. If you do not specify a replacement
element ID, the method appends the recorder as a child of the body element,
centered in the page.
properties (Object) This object can have the following properties (each of which is optional):
setTitle() method of the Recorder object. (Call this method before the recording
starts.) An Archive object includes a title property.true, the user's
selection is remembered in subsequent uses of the OpenTok API.
style object includes the following
properties:"auto" (controls are displayed when the video is first
displayed and when the user mouses over the display), "off" (controls are not displayed),
and "on" (controls are always displayed). The showMicButton and
showSettingsButton properties define whether each individual control is displayed.style property
to control the display of individual buttons.startRecording() method of the Recorder object.)stopRecording() method of the Recorder object.)saveArchive() method of the Recorder object.)wmode values for
the object and embed tags for a SWF file: "opaque",
"transparent" (the default), or "window". (For more information,
see Flash OBJECT and EMBED tag
attributes (at adobe.com).
To remove the recorder from the page, call the removeRecorder() method.
Returns
Recorder The Recorder object.
See
Removes the specified player from the HTML DOM.
Parameters
player (Player) The player to remove.
The application throws an error if the player does not exist in the HTML DOM.
See
Removes the specified recorder from the HTML DOM.
Parameters
recorder (Recorder) The recorder to remove.
The application throws an error if the recorder does not exist in the HTML DOM.
The following code shows you how to use the RecorderManager, Recorder, and Player classes.
var recorderManager;
var recorder;
var player;
var TOKEN = ""; // Replace with a generated token that has been assigned the role of moderator.
// See https://dashboard.tokbox.com/projects
var API_KEY = ""; // Replace with your API key. See https://dashboard.tokbox.com/projects
recorderManager = TB.initRecorderManager(API_KEY);
var recDiv = document.createElement("div");
var recDivId = "recorder" + new Date().getTime().toString();
recDiv.setAttribute("id", recDivId);
document.getElementById("recorderContainer").appendChild(recDiv); // Replace with the ID of the container DOM element.
recorder = recorderManager.displayRecorder(TOKEN, recDivId);
recorder.addEventListener("archiveSaved", archiveSavedHandler);
function archiveSavedHandler(event) {
recorderManager.removeRecorder(recorder);
loadArchive(event.archives[0].archiveId); // You will want to save the archive ID on your server, for future playback.
}
function loadArchive(archiveId) {
playerDiv = document.createElement("div");
var playerDivId = "player" + archiveId;
playerDiv.setAttribute("id", playerDivId);
document.getElementById("playerContainer").appendChild(playerDiv)
player = recorderManager.displayPlayer(archiveId, TOKEN, playerDivId);
}