Skip to content

Added example for p5.MediaElement.play #2231

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 37 additions & 3 deletions lib/addons/p5.dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -1818,10 +1818,44 @@


/**
* Play an HTML5 media element.
* Play an HTML5 media element.
*
* @method play
* @return {Object|p5.Element}
* @method play
* @return {Object|p5.Element}
* @example
* <div><code>
* var ele;
*
* function setup() {
* //p5.MediaElement objects are usually created
* //by calling the createAudio(), createVideo(),
* //and createCapture() functions.
*
* //In this example we create
* //a new p5.MediaElement via createAudio().
* ele = createAudio('assets/beat.mp3');
*
* background(250);
* 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) {
*
* //Here we call the play() function on
* //the p5.MediaElement we created above.
* //This will start the audio sample.
* ele.play();
*
* background(200);
* text("You clicked Play!", width/2, height/2);
* }
* }
* </code></div>
*/
p5.MediaElement.prototype.play = function() {
if (this.elt.currentTime === this.elt.duration) {
Expand Down