Skip to content

Commit 0c14b3d

Browse files
author
Lauren McCarthy
committed
Merge branch 'master' of github.com:processing/p5.js
2 parents 2bb7aa5 + 58866c2 commit 0c14b3d

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

lib/addons/p5.dom.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2008,6 +2008,53 @@
20082008
*
20092009
* @method loop
20102010
* @return {Object|p5.Element}
2011+
* @example
2012+
* <div><code>
2013+
* //Clicking the canvas will loop
2014+
* //the audio sample until the user
2015+
* //clicks again to stop it
2016+
*
2017+
* //We will store the p5.MediaElement
2018+
* //object in here
2019+
* var ele;
2020+
*
2021+
* //while our audio is playing,
2022+
* //this will be set to true
2023+
* var sampleIsLooping = false;
2024+
*
2025+
* function setup() {
2026+
* //Here we create a p5.MediaElement object
2027+
* //using the createAudio() function.
2028+
* ele = createAudio('assets/lucky_dragons_-_power_melody.mp3');
2029+
* background(200);
2030+
* textAlign(CENTER);
2031+
* text("Click to loop!", width/2, height/2);
2032+
* }
2033+
*
2034+
* function mouseClicked() {
2035+
* //here we test if the mouse is over the
2036+
* //canvas element when it's clicked
2037+
* if(mouseX >= 0 && mouseX <= width &&
2038+
* mouseY >= 0 && mouseY <= height) {
2039+
* background(200);
2040+
*
2041+
* if(sampleIsLooping == false) {
2042+
* //loop our sound element until we
2043+
* //call ele.stop() on it.
2044+
* ele.loop();
2045+
*
2046+
* sampleIsLooping = true;
2047+
* text("Click to stop!", width/2, height/2);
2048+
* } else {
2049+
* ele.stop();
2050+
*
2051+
* sampleIsLooping = false;
2052+
* text("Click to loop!", width/2, height/2);
2053+
* }
2054+
* }
2055+
* }
2056+
*
2057+
* </code></div>
20112058
*/
20122059
p5.MediaElement.prototype.loop = function() {
20132060
this.elt.setAttribute('loop', true);

0 commit comments

Comments
 (0)