setPath()函數是p5.js庫中的內置函數。此函數用於重置新路徑的SoundFile的源。
用法:
setPath(path, callback)
注意:僅當index.html文件的開頭部分中包含聲音庫時,所有與聲音相關的函數才起作用。
參數:該函數接受上述和以下所述的兩個參數:
- path:此參數保存新文件的路徑。
- callback:此參數是將被調用的函數的名稱。
下麵的示例說明了JavaScript中的p5.setPath()函數:
var sound;
function preload() {
// Initialize sound
sound = loadSound("pfivesound.mp3");
sounds = loadSound("pfivesounds.mp3")
}
function setup() {
// Playing the preloaded sound
sound.play();
//sound will play twice fast
sound.setpath(sounds/pfivesound.mp3, gfg);
}
function gfg() {
alert("setPath function called successfully")
}
在線編輯: https://editor.p5js.org/
環境設置: https://www.geeksforgeeks.org/p5-js-soundfile-object-installation-and-methods/
支持的瀏覽器:下麵列出了p5.js setPath()函數支持的瀏覽器:
- 穀歌瀏覽器
- IE瀏覽器
- Firefox
- Safari
- Opera
相關用法
- p5.js int()用法及代碼示例
- p5.js nfp()用法及代碼示例
- p5.js value()用法及代碼示例
- p5.js nfs()用法及代碼示例
- PHP each()用法及代碼示例
- PHP Ds\Set first()用法及代碼示例
- PHP Ds\Set last()用法及代碼示例
- p5.js log()用法及代碼示例
- p5.js cos()用法及代碼示例
- p5.js min()用法及代碼示例
- p5.js red()用法及代碼示例
注:本文由純淨天空篩選整理自skyridetim大神的英文原創作品 p5.js | setPath() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。