MCPcopy
hub / github.com/processing/p5.js / play

Method play

src/dom/p5.MediaElement.js:112–140  ·  view source on GitHub ↗

* Plays audio or video from a media element. * * @chainable * * @example * let beat; * * function setup() { * createCanvas(100, 100); * * background(200); * * // Style the text. * textAlign(CENTER); * textSize(16); * * // Display a message.

()

Source from the content-addressed store, hash-verified

110 * }
111 */
112 play() {
113 if (this.elt.currentTime === this.elt.duration) {
114 this.elt.currentTime = 0;
115 }
116 let promise;
117 if (this.elt.readyState > 1) {
118 promise = this.elt.play();
119 } else {
120 // in Chrome, playback cannot resume after being stopped and must reload
121 this.elt.load();
122 promise = this.elt.play();
123 }
124 if (promise && promise.catch) {
125 promise.catch(e => {
126 // if it's an autoplay failure error
127 if (e.name === 'NotAllowedError') {
128 if (typeof IS_MINIFIED === 'undefined') {
129 p5._friendlyAutoplayError(this.src);
130 } else {
131 console.error(e);
132 }
133 } else {
134 // any other kind of error
135 console.error('Media play method encountered an unexpected error', e);
136 }
137 });
138 }
139 return this;
140 }
141
142 /**
143 * Stops a media element and sets its current time to 0.

Callers 2

loopMethod · 0.95
mediaFunction · 0.45

Calls

no outgoing calls

Tested by

no test coverage detected