let currVolume = 0.5;
function
setup() {
createCanvas(500, 400);
textSize(18);
text(
"Click on the buttons to increase "
+
"or decrease the volume"
, 20, 20);
example_media =
createVideo(
"sample-video.mp4"
);
example_media.size(500, 300);
example_media.position(20, 100);
example_media.showControls();
example_media.volume(currVolume);
incBtn = createButton(
"Increase Volume"
);
incBtn.position(30, 40);
incBtn.mousePressed(incVol);
decBtn = createButton(
"Decrease Volume"
);
decBtn.position(160, 40);
decBtn.mousePressed(decVol);
text(
"The video is playing at "
+
"half volume"
, 20, 80);
}
function
incVol() {
clear();
if
(currVolume < 0.9)
currVolume += 0.1;
example_media.volume(currVolume);
text(
"The volume has been increased"
,
20, 80);
text(
"Click on the buttons to increase "
+
"or decrease the volume"
, 20, 20);
}
function
decVol() {
clear();
if
(currVolume > 0.1)
currVolume -= 0.1;
example_media.volume(currVolume);
text(
"The volume has been decreased"
,
20, 80);
text(
"Click on the buttons to increase "
+
"or decrease the volume"
, 20, 20);
}