Skip to content

Commit cc4a489

Browse files
authored
Merge pull request #2231 from bomoko/Documentation/Add_p5_MediaElement_play_example
Added example for p5.MediaElement.play
2 parents d8a6fc2 + 69f0b2b commit cc4a489

File tree

1 file changed

+37
-3
lines changed

1 file changed

+37
-3
lines changed

lib/addons/p5.dom.js

+37-3
Original file line numberDiff line numberDiff line change
@@ -1818,10 +1818,44 @@
18181818

18191819

18201820
/**
1821-
* Play an HTML5 media element.
1821+
* Play an HTML5 media element.
18221822
*
1823-
* @method play
1824-
* @return {Object|p5.Element}
1823+
* @method play
1824+
* @return {Object|p5.Element}
1825+
* @example
1826+
* <div><code>
1827+
* var ele;
1828+
*
1829+
* function setup() {
1830+
* //p5.MediaElement objects are usually created
1831+
* //by calling the createAudio(), createVideo(),
1832+
* //and createCapture() functions.
1833+
*
1834+
* //In this example we create
1835+
* //a new p5.MediaElement via createAudio().
1836+
* ele = createAudio('assets/beat.mp3');
1837+
*
1838+
* background(250);
1839+
* textAlign(CENTER);
1840+
* text("Click to Play!", width/2, height/2);
1841+
* }
1842+
*
1843+
* function mouseClicked() {
1844+
* //here we test if the mouse is over the
1845+
* //canvas element when it's clicked
1846+
* if(mouseX >= 0 && mouseX <= width &&
1847+
* mouseY >= 0 && mouseY <= height) {
1848+
*
1849+
* //Here we call the play() function on
1850+
* //the p5.MediaElement we created above.
1851+
* //This will start the audio sample.
1852+
* ele.play();
1853+
*
1854+
* background(200);
1855+
* text("You clicked Play!", width/2, height/2);
1856+
* }
1857+
* }
1858+
* </code></div>
18251859
*/
18261860
p5.MediaElement.prototype.play = function() {
18271861
if (this.elt.currentTime === this.elt.duration) {

0 commit comments

Comments
 (0)