複数のフォーマットでビデオを読み込み、ボタンを押して再生と一時停止を切り替えます。
video media play/pause
DOM Video
View Source Code
/*
* @name Video
* @arialabel Video of fingers walking
* @frame 710,250
* @description Load a video with multiple formats and toggle between playing
* and paused with a button press.
*/
let playing = false;
let fingers;
let button;
function setup() {
noCanvas();
// specify multiple formats for different browsers
// fingers = createVideo(['assets/fingers.mov', 'assets/fingers.webm']);
fingers = createVideo(['../../../../p5js-website-legacy-examples/assets/fingers.mov', '../../../../p5js-website-legacy-examples/assets/fingers.webm']);
button = createButton('play');
button.mousePressed(toggleVid); // attach button listener
}
// plays or pauses the video depending on current state
function toggleVid() {
if (playing) {
fingers.pause();
button.html('play');
} else {
fingers.loop();
button.html('pause');
}
playing = !playing;
}
License
Source code is available on GitHub p5.js website legacy.
All examples are licensed under CC BY-NC-SA 4.0.