recordingSaved()#
事件oav-p5function recordingSaved(info) {}
一個由你定義的事件函式:錄影存好、檢查完之後呼叫它,帶著一個說明這支檔案的 info 物件。
定義 function recordingSaved(info) { … },就知道檔案什麼時候好了:stopRecording() 或 seconds 時間到之後會走到這裡。那時檔案已經交給瀏覽器下載了。同一份 info 也會交給 stopRecording() 回傳的 promise 和 OAVp5.record.on('saved', fn),並且留在 OAVp5.record.last。
info.url 可以當成檔案的連結用(createA(info.url, 'play') 或 <video>),直到下一支錄好之後一分鐘為止。warnings 是錄完之後卡片用文字說的那些事,空的清單表示沒有哪裡不對。
參數
| 名稱 | 型別 | 說明 |
|---|---|---|
info | Object | name(檔名)、format('mp4' 或 'webm')、type(精確的 MIME 類型)、seconds(長度,精確到 0.1 秒)、bytes、width 和 height(MP4 會是偶數)、fps、audio(影片有沒有音軌)、heard(有沒有真的出過聲)、sources(錄進去的聲音來源:'sound'、'drums'、'mic'、'p5sound')、warnings(看起來哪裡不對:'recEmpty'、'recWebm'、'recNoAudio'、'recSilent'、'recBlack',通常是空的)、blob(檔案本身)、url(blob 的位址)。 |
範例
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);
}
}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);
}相關
startRecording()把畫布和草圖發出的聲音錄成一支影片檔,並回傳一個 promise,告訴你錄影有沒有開始。stopRecording()停止錄影,影片完成後會下載,並交給recordingSaved(info)和回傳的 promise。OAVp5.record.last最近一支存好的錄影的info(跟recordingSaved拿到的是同一個物件),第一支之前是null。OAVp5.record.on()在任何地方監聽錄影:OAVp5.record.on('saved', fn)或on('start', fn),並回傳一個可以取消監聽的函式。recordingIsOn現在有沒有在錄影。