Skip to content

Commit

Permalink
Merge pull request #2237 from bomoko/Documentation/p5_MediaElement_stop
Browse files Browse the repository at this point in the history
Added p5.MediaElement.stop example
  • Loading branch information
lmccart authored Oct 4, 2017
2 parents cc4a489 + bb4330b commit e637fb6
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions lib/addons/p5.dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -1877,6 +1877,61 @@
*
* @method stop
* @return {Object|p5.Element}
* @example
* <div><code>
*
* //This example both starts
* //and stops a sound sample
* //when the user clicks the canvas
*
* //We will store the p5.MediaElement
* //object in here
* var ele;
*
* //while our audio is playing,
* //this will be set to true
* var sampleIsPlaying = false;
*
* function setup() {
* //Here we create a p5.MediaElement object
* //using the createAudio() function.
* ele = createAudio('assets/beat.mp3');
* background(200);
* textAlign(CENTER);
* text("Click to play!", width/2, height/2);
* }
*
* function mouseClicked() {
* //here we test if the mouse is over the
* //canvas element when it's clicked
* if(mouseX >= 0 && mouseX <= width &&
* mouseY >= 0 && mouseY <= height) {
* background(200);
*
* if(sampleIsPlaying) {
* //if the sample is currently playing
* //calling the stop() function on
* //our p5.MediaElement will stop
* //it and reset its current
* //time to 0 (i.e. it will start
* //at the beginning the next time
* //you play it)
* ele.stop();
*
* sampleIsPlaying = false;
* text("Click to play!", width/2, height/2);
* } else {
* //loop our sound element until we
* //call ele.stop() on it.
* ele.loop();
*
* sampleIsPlaying = true;
* text("Click to stop!", width/2, height/2);
* }
* }
* }
*
* </code></div>
*/
p5.MediaElement.prototype.stop = function() {
this.elt.pause();
Expand Down

0 comments on commit e637fb6

Please sign in to comment.