Skip to content

Commit c8dcf80

Browse files
committed
First draft
1 parent 841a55b commit c8dcf80

2 files changed

Lines changed: 32 additions & 0 deletions

File tree

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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+
}
3.12 MB
Binary file not shown.

0 commit comments

Comments
 (0)