xxxxxxxxxx
49
let song,
volumeSlider,
rateSlider,
panSlider,
playButton,
jumpButton;
function preload() {
song = loadSound("1.1.mp3");
}
function setup() {
createCanvas(400, 400);
volumeSlider = createSlider(0, 1, 0.2, 0.01);
rateSlider = createSlider(0, 1.5, 1, 0.01);
panSlider = createSlider(-1, 1, 0, 0.01);
playButton = createButton("");
playButtonClick();
playButton.mousePressed(playButtonClick);
jumpButton = createButton("Jump");
jumpButton.mousePressed(jumpButtonClick);
}
function draw() {
background((song.currentTime() > 5) ? 22 : 233);
song.setVolume(volumeSlider.value());
song.rate(rateSlider.value());
song.pan(panSlider.value());
fill(233);
noStroke();
text("Volume", 0, 20);
}
function playButtonClick() {
let buttonText;
if (song.isPlaying()) {
song.pause();
buttonText = "Play";
} else {
song.play();
buttonText = "Pause";
}
playButton.html(buttonText);
}
function jumpButtonClick() {
song.jump(random(song.duration()));
}