|
2008 | 2008 | * |
2009 | 2009 | * @method loop |
2010 | 2010 | * @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> |
2011 | 2058 | */ |
2012 | 2059 | p5.MediaElement.prototype.loop = function() { |
2013 | 2060 | this.elt.setAttribute('loop', true); |
|
0 commit comments