p5.MediaElement speed() Method
The speed() method of p5.MediaElement in p5.js is used to set or return the current playback speed of the media element. It accepts a single parameter that denotes the speed multiplier to be used for media playback. A value of 2.0 would play the media at double speed and a value of 0.5 would play it at half the speed. Negative values can also be specified to play the media in reverse, however, it may not be properly supported in all browsers.
The current playback speed of the media can be returned by not passing any parameter to the function.
speed( speed )
Parameters: This method accepts a single parameter as mentioned above and described below:
- speed: It is a number that specifies the multiplier to be used for the playback speed. It is an optional parameter.
Return Value: This method returns a Number that denotes the current playback speed of the media element.
The examples below illustrate the speed() method in p5.js:
Online editor: https://editor.p5js.org/
Environment Setup: https://www.geeksforgeeks.org/p5-js-soundfile-object-installation-and-methods/