'sustain' モードでは、サウンドはそれ自体と重なります。'restart' モードでは、停止してから再開します。マウスをクリックしてサウンドファイルを再生します。一度にたくさんの音を鳴らしてみましょう!任意のキーを押してプレイモードを変更します。
playMode sustain restart
Sound Interaction
View Source Code
/*
* @name Play Mode
* @arialabel Yellow screen plays music when user clicks on it
* @description
* <p>In 'sustain' mode, the sound will overlap with itself.
* In 'restart' mode it will stop and then start again.
* Click mouse to play a sound file.
* Trigger lots of sounds at once! Press any key to change playmode.</p>
* <p><em><span class="small"> To run this example locally, you will need the
* <a href="http://p5js.org/reference/#/libraries/p5.sound">p5.sound library</a>
* a sound file, and a running <a href="https://github.com/processing/p5.js/wiki/Local-server">local server</a>.</span></em></p>
*/
let playMode = 'sustain';
let sample;
function setup() {
// createCanvas(710, 50);
createCanvas(windowWidth, windowHeight);
soundFormats('mp3', 'ogg');
// sample = loadSound('assets/Damscray_-_Dancing_Tiger_02.mp3');
sample = loadSound('../../../../p5js-website-legacy-examples/assets/Damscray_-_Dancing_Tiger_02.mp3');
}
function draw() {
background(255, 255, 0);
let str = 'Click here to play! Press key to toggle play mode.';
str += ' Current Play Mode: ' + playMode + '.';
text(str, 10, height / 2);
}
function mouseClicked() {
sample.play();
}
function keyPressed(k) {
togglePlayMode();
}
function togglePlayMode() {
if (playMode === 'sustain') {
playMode = 'restart';
} else {
playMode = 'sustain';
}
sample.playMode(playMode);
}
License
Source code is available on GitHub p5.js website legacy.
All examples are licensed under CC BY-NC-SA 4.0.