I am building a children's app which have several different audio tracks depending on which page you are on, they auto play. I inserted them as html5 audio.
I created a mute button which can stop the audio. However, the problem i have is that when you navigate to a different page the music will start playing again.
What i need is some kind of mute button that will stop all audio in the app and for it to 'remember' the setting. Maybe a cookie or something i dont know the best solution, can anyone help and suggest?
On/off button for all music in app
On/off button for all music in app
You can set a local storage variable and check the status on page load or show.
var playMusic = localStorage.getItem('canPlay');
if (playMusic == "true") {
// do something
}
var playMusic = localStorage.getItem('canPlay');
if (playMusic == "true") {
// do something
}
-
- Posts: 0
- Joined: Sun Dec 13, 2015 1:08 am
On/off button for all music in app
Thanks yes i think local storage variable would be the answer. Need to figure out the script then....
-
- Posts: 0
- Joined: Sun Dec 13, 2015 1:08 am
On/off button for all music in app
Your code was missleading...
I had to use
var playMusic = localStorage.getItem('playMusic');
if (playMusic == "true") {
// do something
}
what was the canPlay part about?! took me ages to spot that
I had to use
var playMusic = localStorage.getItem('playMusic');
if (playMusic == "true") {
// do something
}
what was the canPlay part about?! took me ages to spot that
-
- Posts: 0
- Joined: Sun Dec 13, 2015 1:08 am
On/off button for all music in app
Now I have a new issue with audio playback, if anyone can help see here: https://getsatisfaction.com/apperyio/...
Re: On/off button for all music in app
That is actually quite difficult for beginners like me.
-
- Posts: 1
- Joined: Tue Dec 01, 2020 6:31 am
Re: On/off button for all music in app
Use this code
var playMusic = localStorage.getItem('playMusic');
if (playMusic == "true") {
// do something
}