Programmatic Webcam Control


Please note – the Collect API is not available for new signups anymore.


On top of the Custom Button API you can programmatically control the webcam recorder, ie., without requiring user interactions. You should combine the programmatic webcam control with the onWebcamStatusChange callback, which will allow you to keep state in your code in sync with the actual state of the webcam recorder. The call of the Custom Button API returns a Javascript Promise, which resolves into a webcam API object when the Clipchamp widget is shown:

  1. <script type="text/javascript">
  2. var process = clipchamp({
  3. inputs: ['camera'], // go directly to the webcam
  4. enable: [
  5. 'no-thank-you', // close widget after upload and skip final 'Thank you' screen
  6. 'no-user-retry', // directly upload video after finishing recording
  7. 'mobile-webcam-format-fallback' // use inline recorder in Chrome on Android
  8. ],
  9. onWebcamStatusChange: function(status) {
  10. // handle current webcam and recording status (optional)
  11. }
  12. });
  13. {
  14. // Webcam widget is now open.
  15. // First check if webcam/phone camera is ready:
  16. remote.areRecordingDevicesReady().then(function() {
  17. // Webcam/camera can be used on this browser/device.
  18. // Now call remote.startRecording() to start recording.
  19. }).catch(function() {
  20. // webcam/camera not accessible on this browser/device
  21. });
  22. });
  23. </script>

We recommend to initially call the areRecordingDevicesReady() function, which resolves if the webcam can be successfully accessed and recording is generally possible. You can use this call as a “preflight” check to confirm that the subsequent calls can be performed. Please note that areRecordingDevicesReady may require a user interaction to approve a browser popup that prompts the browser to approve the domain to access the webcam and microphone. Once approved, the corresponding permission is typically stored in the browser profile, but may be revoked at any time as a result of the user clearing out the browser cache, using the browser’s incognito mode, new hardware devices becoming available or other incidents. Hence, it is a good idea to precede every invocation of the programmatic webcam control API by an areRecordingDevicesReady() call. The other functions of the programmatic webcam control API are:

  • startRecording(): Starts the recording if the Clipchamp widget shows the webcam screen and the webcam capture is on.
  • pauseRecording(): Pauses the recording if a recording was previously started and is not currently paused.
  • resumeRecording(): Resumes the recording if a recording was previously started and is currently paused.
  • finishRecording(): Finishes the recording and triggers the subsequent processing of the video.
  • cancelRecording(): Aborts a recording and closes the Clipchamp widget.

All of these functions are asynchronous and may return before the corresponding action is complete. Please use the onWebcamStatusChange callback to synchronize any state on your side with the actual state of the webcam recorder. If a function of the webcam control API is called and the webcam recorder is in an incompatible state, the call may not be queued for later execution when the webcam recorder has reached the correct state. For instance, the behavior of the webcam control API is not defined when you call startRecording(), but the onWebcamStatusChange callback has not previously signaled that the webcam capture was successfully switched on (capture_started).