p5.js | playMode() Function
The playMode() function is an inbuilt function in p5.js library. This function is used to define what is happening with the loaded audio if it is triggered while in the middle of playback or not. This function is useful when you want to restart the sound during the loading time of the website, without this function the sound can be played on mouseclick or keypressed action but that does not stop the previously played sound.
playMode( string )
Note: All the sound-related functions only work when the sound library is included in the head section of the index.html file.
Parameter: This function accept a single parameter string that has two values mentioned above and described below, the default value is ‘sustain’:
- string: This parameter has two values those are restart In this mode the paly() will stop playback and start over. The sustain In this mode playback will continue simultaneously to the new playback.
Online editor: https://editor.p5js.org/
Environment Setup: https://www.geeksforgeeks.org/p5-js-soundfile-object-installation-and-methods/
Supported Browsers: The browsers are supported by p5.js playMode() function are listed below:
- Google Chrome
- Internet Explorer