Skip to content
Advertisement

PHP music play/pause button

Hi, i am working on a project where i have a music button which is used to start/play and stop/pause the background music. PROBLEM: Problem is that i have many pages in my website when i press the music stop/pause button the music stops playing but when i navigate to different pages the music starts automatically and i again need to press the button on every new page loaded to stop the music playing on background.Solution Needed i want solution that if i press the music stop button the music must stop for the whole website until i again press the button to play the music.

JavaScript
JavaScript

Advertisement

Answer

use localStorage

1) when user click pause button set the item localStorage.setItem(‘music’,’stop’); an each page load check the localstorage and pause audio like this.

JavaScript

2) when user click play button set the item localStorage.setItem(‘music’,’play’);

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement