}
let pause = () => {
audioFile.pause()
}
let stop = () => {
audioFile.pause()
audioFile.currentTime = 0
}
let updateVolumeIndicator = () => {
volIndicator.innerText = vol
}
let roundVolume = () => {
vol = audioFile.volume.toFixed(1)
audioFile.volume = vol
}
let volUp = () => {
if(audioFile.volume < 1) {
audioFile.volume += 0.1
} else {
audioFile.volume = 1
}
roundVolume()
updateVolumeIndicator()
}
let volDown = () => {
if(audioFile.volume > 0) {
audioFile.volume -= 0.1
} else {
audioFile.volume = 0
}
roundVolume()
updateVolumeIndicator()
}
playBtn.addEventListener('click', play)
pauseBtn.addEventListener('click', pause)
stopBtn.addEventListener('click', stop)
volumeDown.addEventListener('click', volDown)
volumeUp.addEventListener('click', volUp)
// Stretch goals:
// - Add volume controls.
// - Allow the user to select different sounds.
const playBtn = document.getElementById("play-btn")
const pauseBtn = document.getElementById("pause-btn")
const stopBtn = document.getElementById("stop-btn")
const audioFile = new Audio('./bells.mp3')
const volumeUp = document.getElementById('up')
const volumeDown = document.getElementById('down')
const volIndicator = document.getElementById('volume')
let vol = 1;
// Task:
// - Add the functionality to play, pause and stop the jingling bells (bells.mp3).
let play = () => {
audioFile.play();