File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ /**
2+ * @name Create Audio
3+ * @description <a href="https://p5js.org/reference/#/p5/createAudio" target="_blank">createAudio()</a>
4+ * creates an audio player. This example displays the player's controls
5+ * and adjusts its speed. The playback speed is normal when the mouse
6+ * is on the left edge of the window, and it gets faster as the mouse
7+ * moves to the right. More information on using media elements such as
8+ * audio players is on the
9+ * <a href="https://p5js.org/reference/#/p5.MediaElement" target="_blank">p5.MediaElement</a>
10+ * reference page. The audio file is a
11+ * <a href="https://freesound.org/people/josefpres/sounds/711156/" target="_blank">
12+ * public domain piano loop by Josef Pres</a>.
13+ */
14+
15+ // Declare variable to store audio player
16+ let audioPlayer ;
17+
18+ function setup ( ) {
19+ // Remove canvas
20+ noCanvas ( ) ;
21+
22+ // Create audio player using path to audio file
23+ audioPlayer = createAudio ( "assets/piano-loop.mp3" ) ;
24+
25+ // Display player controls
26+ audioPlayer . showControls ( ) ;
27+ }
28+
29+ function draw ( ) {
30+ // Set playback speed to 1-2x normal based on mouse position
31+ audioPlayer . speed ( 1 + mouseX / windowWidth ) ;
32+ }
You can’t perform that action at this time.
0 commit comments