Skip to content
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

Added example for p5.MediaElement.volume() #2293

Closed
wants to merge 1 commit into from
Closed
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
36 changes: 35 additions & 1 deletion lib/addons/p5.dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -2086,13 +2086,47 @@
return this;
};

/**
/*
* Sets volume for this HTML5 media element. If no argument is given,
* returns the current volume.
*
* @param {Number} [val] volume between 0.0 and 1.0
* @return {Number|p5.MediaElement} current volume or p5.MediaElement
* @method volume
*
* @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/lucky_dragons_-_power_melody.mp3');
* background(250);
* textAlign(CENTER);
* text("Click to Play!", width/2, height/2);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you remove the extra tab here


* }

* 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 volume() function
* //on the sound element to set its volume
* //Volume must be between 0.0 and 1.0
* ele.volume(0.2)
* ele.play();
* background(200);
* text("You clicked Play!", width/2, height/2);
* }
* }
* </code></div>
*/
p5.MediaElement.prototype.volume = function(val) {
if (typeof val === 'undefined') {
Expand Down