p5.js MediaElement clearCues() 方法
p5.j s库的p5.MediaElement的clearCues()方法用于清除已使用addCue()方法调度的媒体元素的所有当前调度的 cue。
句法:
clearCues()
参数:此函数不接受任何参数。
以下库包含在 HTML 文件的“head”部分中,以便 JavaScript 函数正常工作。
示例:下面的示例说明了p5.js库的clearCues()方法。
Javascript
function setup() {
createCanvas(550, 400);
textSize(18);
text("The events in addCue() are " +
"called according to the given time",
20, 20);
example_media =
createVideo("sample-video.mp4");
example_media.size(426, 240);
example_media.position(20, 60);
example_media.speed(1.5);
example_media.showControls();
rmvBtn =
createButton("Remove All Cues");
rmvBtn.position(20, 320);
rmvBtn.mousePressed(removeCues)
// Using the addCue() method for scheduling
// the given callback functions
example_media.addCue(3, changeColor);
example_media.addCue(4, changeColor);
example_media.addCue(5, changeColor);
example_media.addCue(7, changeColor);
}
function removeCues() {
clear();
// Remove all cues associated with
// the media element
example_media.clearCues();
text("All cues removed!", 20, 360);
text("The clearCues() method removes " +
"all the current cues", 20, 20);
}
function changeColor() {
// Set a random background color
r = random(100, 200);
g = random(100, 200);
b = random(100, 200);
background(r, g, b);
text("Background Color Changed!",
20, 360);
text("The events in addCue() are " +
"called according to the given time",
20, 20);
}
输出:
在线编辑器: https://editor.p5js.org/
环境设置: https://www.geeksforgeeks.org/p5-js-soundfile-object-installation-and-methods/
参考: https://p5js.org/reference/#/p5.MediaElement/clearCues