open-audiovisual
Search GitHub

oav-p5 reference · Recording

recordingSaved()#

eventoav-p5
function recordingSaved(info) {}

An event you define: it is called when a recording has been saved and checked, with an info object about the file.

Define function recordingSaved(info) { … } to know when the file is done: stopRecording() or the end of seconds leads to it. By then the file has already been handed to the browser to download. The same info is given to the promise of stopRecording() and to OAVp5.record.on('saved', fn), and stays in OAVp5.record.last.

info.url works as a link to the file (createA(info.url, 'play') or a <video>) until a minute after the next take is saved. warnings is what the card after the take says in words; an empty list means nothing looked wrong.

Parameters

NameTypeDescription
infoObjectname (the file name), format ('mp4' or 'webm'), type (the exact MIME type), seconds (length, to a tenth), bytes, width and height (even numbers for MP4), fps, audio (the video has a sound track), heard (something sounded), sources (which sounds were in it: 'sound', 'drums', 'mic', 'p5sound'), warnings (what looked wrong: 'recEmpty', 'recWebm', 'recNoAudio', 'recSilent', 'recBlack', usually an empty list), blob (the file) and url (an address for the blob).

Examples

jsOpenProcessing ↗
let saved = '';

function setup() {
  createCanvas(400, 300);
}

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

function recordingSaved(info) {
  saved = info.name + '  ' + info.format + '  ' + info.seconds + ' s  ' + round(info.bytes / 1024) + ' KB';
}

function draw() {
  background(20);
  circle(200 + sin(frameCount * 0.05) * 120, 150, 50);
  if (!recordingIsOn) {
    fill(255);
    text(saved || 'press r to record 3 seconds', 20, 30);
  }
}
Press r: three seconds later the file is downloaded and its name, format, length and size appear on the canvas.
jsOpenProcessing ↗
let note = '';

function setup() {
  createCanvas(400, 300);
  startDrums('breakbeat', 120);
}

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

function recordingSaved(info) {
  note = info.heard ? 'with sound: ' + info.sources.join(', ') : 'silent: click the page before you record';
  if (info.warnings.length) note += '  (' + info.warnings.join(', ') + ')';
}

function draw() {
  background(20);
  fill(255);
  if (!recordingIsOn) text(note || 'click once, then press r', 20, 30);
}
Press r (after one click on the page): the text says whether the video has sound, from which sources, and lists anything that looked wrong.

Related

  • startRecording() Records the canvas and the sound your sketch makes into one video file, and returns a promise that says whether the recording began.
  • stopRecording() Stops the recording; the video is finished, downloaded, and handed to recordingSaved(info) and to the returned promise.
  • OAVp5.record.last The info of the last recording that was saved (the same object recordingSaved got), or null before the first one.
  • OAVp5.record.on() Listens to the recording from anywhere: OAVp5.record.on('saved', fn) or on('start', fn), and it returns a function that stops listening.
  • recordingIsOn Whether a recording is running right now.

p5/oav-p5.js, line 1940

↑ Back to top · All names