Intercepting events of the player

You are an experienced programmer and you do not fear JavaScript? Excellent! The Nimbb Player offers great flexibility to implement it in your most complex projects.

To do so, you can intercept events generated by our player. Simply define the function of the event in your code. In this example, you will see the events generated when you use Nimbb.

Tip: notice the two links that allow you to easily switch from viewer to recorder!

This example requires you to specify your developer key (see tutorial).

Example

view mode record mode clear logs
Disable logging of stateChanged events.

HTML code

<script language="JavaScript" type="text/javascript">
<!--

// Global variable to hold player's reference.
var _Nimbb;

// Event: Nimbb Player has been initialized and is ready.
function Nimbb_initCompleted(idPlayer)
{
  // Get a reference to the player since it was successfully created.
  _Nimbb = document[idPlayer];
  log("initCompleted");
}

// Event: the player is being initialized and not yet ready.
function Nimbb_initStarted(idPlayer)
{
  log("initStarted");
}

// Event: the mode of the player changed.
function Nimbb_modeChanged(idPlayer, mode)
{
  log("modeChanged -> " + mode);
}

// Event: the state of the player changed.
function Nimbb_stateChanged(idPlayer, state)
{
  var checkbox = document.getElementById("stateCheckBox");
	
  // Since this event is called often, make sure we want to log it.
  if(!checkbox.checked)
  {
    log("stateChanged -> " + state);
  }
}

// Event: the player has started playing.
function Nimbb_playbackStarted(idPlayer)
{
  log("playbackStarted");
}

// Event: the player has stopped playing.
function Nimbb_playbackStopped(idPlayer, endReached)
{
  log("playbackStopped -> " + endReached);
}

// Event: the player has started recording.
function Nimbb_recordingStarted(idPlayer)
{
  log("recordingStarted");
}

// Event: the player has stopped recording.
function Nimbb_recordingStopped(idPlayer)
{
  log("recordingStopped");
}

// Event: the maximum recording length has changed.
function Nimbb_recordLengthChanged(idPlayer, seconds)
{
  log("recordLengthChanged -> " + seconds);
}

// Event: the video was saved.
function Nimbb_videoSaved(idPlayer)
{
  log("videoSaved");
}

// Event: the volume of the player changed.
function Nimbb_volumeChanged(idPlayer, volume)
{
  log("volumeChanged -> " + volume);
}

// Event: the user changed privacy settings for allowing access to camera/microphone.
function Nimbb_captureChanged(idPlayer, allowed)
{
  log("captureChanged -> " + allowed);
}

// Event: the player did not detect a camera.
function Nimbb_noCameraDetected(idPlayer)
{
  log("noCameraDetected");
}

// Event: the player did not detect a microphone.
function Nimbb_noMicroDetected(idPlayer)
{
  log("noMicroDetected");
}

// Set mode of the player (view/record).
function setMode(mode)
{
  _Nimbb.setMode(mode);
}

// Add log to textbox.
function log(text)
{
  var box = document.getElementById("logTextBox");
  box.value = text + "\n" + box.value ;
}

// Clear textbox.
function clearLogs()
{
  var box = document.getElementById("logTextBox");
  box.value = "";
}

// -->
</script>
<a href="javascript:setMode('view');">view mode</a>
<a href="javascript:setMode('record');">record mode</a>
<a href="javascript:clearLogs();">clear logs</a>
<br>

<object id="nimbb" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="320" height="240" codebase= "http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab">
<param name="movie" value="http://player.nimbb.com/nimbb.swf?guid=XXXXXXXXXX&key=XXXXXXXXXX&lang=en" />
<param name="allowScriptAccess" value="always" />
<embed name="nimbb" src="http://player.nimbb.com/nimbb.swf?guid=XXXXXXXXXX&key=XXXXXXXXXX&lang=en" width="320" height="240" allowScriptAccess="always" pluginspage="http://www.adobe.com/go/getflashplayer" type="application/x-shockwave-flash">
</embed>
</object>

<textarea id="logTextBox" rows="14" cols="20" style="width:320px;height:240px;"></textarea>

<br>
<input id="stateCheckBox" type="checkbox"> Disable logging of stateChanged events.

All JavaScript functions starting with "Nimbb_" are events. By declaring an event in your code, the Nimbb Player will call it. You can declare only the events you want to intercept for your project.

You can also see the setMode(mode) method. This function call allows you to switch from the viewer to the recorder.

View more tutorials.

SIGN UP NOW 7-day free trial

Check out our Developer guide to get started with Nimbb.