open-audiovisual
Search GitHub

oav-p5 reference · Recording

OAVp5.record.on()#

functionoav-p5
OAVp5.record.on(name, fn)

Listens to the recording from anywhere: OAVp5.record.on('saved', fn) or on('start', fn), and it returns a function that stops listening.

recordingSaved() is a single function that you define. on() is for the cases where that does not fit: several listeners, a library, a listener you want to remove again. It is the same idea as OAVp5.drums.on() and midi.on(). An error thrown inside fn is printed and the other listeners still run.

Parameters

NameTypeDescription
nameString'start' (a take began) or 'saved' (a file is saved, like recordingSaved()). Any other name throws an error that lists the two.
fnFunctionFor 'start' it gets { width, height, fps, type, seconds } (seconds is 0 when no length was asked for). For 'saved' it gets the same info as recordingSaved().

Returns

Function A function: call it to stop listening.

Examples

jsOpenProcessing ↗
let status = 'press r to record 2 seconds';

function setup() {
  createCanvas(400, 300);
  OAVp5.record.on('start', (i) => { status = 'recording ' + i.width + 'x' + i.height + ' at ' + i.fps + ' fps'; });
  OAVp5.record.on('saved', (i) => { status = 'saved ' + i.name; });
}

function keyPressed() {
  if (key === 'r') startRecording(2);
}

function draw() {
  background(20);
  circle(200 + sin(frameCount * 0.05) * 120, 150, 50);
  if (!recordingIsOn) {
    fill(255);
    text(status, 20, 30);
  }
}
Press r: the text reports the start (size and frame rate) and then the saved file name, from two listeners.

Related

  • recordingSaved() An event you define: it is called when a recording has been saved and checked, with an info object about the file.
  • startRecording() Records the canvas and the sound your sketch makes into one video file, and returns a promise that says whether the recording began.
  • OAVp5.drums.on() Listens to the drum machine from anywhere: OAVp5.drums.on('hit', fn) calls fn like drumHit does, and returns a function that stops listening.
  • OAVp5.record The object behind the recording names: the state, the time, the last file, the formats this browser can write and the screenshot function.

p5/oav-p5.js, line 1926

↑ Back to top · All names