Reputation: 11
So im using Howler to play background music when my React app is loaded. So I store ID of the instance of Howler(i.e is responsible for background music) using useState hook. I have a button in the app to toggle pause and play in the app. The problem is, when ever my site rerenders, a new instance is started playing and when I pause nothing pauses.
const [aid, setAid] = useState(null);
const [sp, setSp] = useState(false);
function handleBgSound() {
if (sp) {
amb.pause(aid);
setSp(false)
}
else if (!sp) {
setAid(amb.play())
setSp(true)
} else {
amb.pause();
}
}
Im frustrated with this and would appreciate any help or leads!!
Upvotes: 1
Views: 1208