Answer the question
In order to leave comments, you need to log in
How to control the audio block from another tab or determine the status of this block?
Good day, Toster and its visitors.
On one of the pages of my site, I have an audio file playing. To be more precise - one of the three files. The file itself is selected dynamically by the PHP code (I use the Smarty template engine), depending on some data, when the page is opened. But all three files are written to the audio block with the same ID. Looks like this:
<audio id="PageSound" preload="auto">
<source src="./sounds/{$sound}.mp3"></source>
<source src="./sounds/{$sound}.ogg"></source>
</audio>
mysite.ru/Page.php?data="get-data"
function playTimePageSound()
{
var playTime = new Date().getTime() / 1000;
playTime += 5;
setCookie('PageSound', playTime, 1);
window.setTimeout(playTimePageSound, 4000);
}
jQuery(document).ready(function()
{
var nowTime = new Date().getTime() / 1000;
PageSoundStatus = getCookie('PageSound');
if(PageSoundStatus == undefined)
PageSoundStatus = 0;
if(PageSoundStatus < nowTime)
{
var PageSound = document.getElementById('PageSound');
PageSound.play();
playTimePageSound();
}
});
mysite.ru/Page.php
and the playback status of the block <audio id="PageSound">
? That is, I want to determine if an audio file is played somewhere in some window or tab with such a page, then a new one will not start. If it is not reproduced anywhere, then we start playback. Since playback of a file can be stopped with PageSound.pause();
, this must also be taken into account as a block that is not played back (for example if(PageSound.paused){}
). Answer the question
In order to leave comments, you need to log in
Communication between browser tabs can be organized by subscribing to changes in localstorage data and writing the necessary commands to it.
By the way. Now I noticed that my question was signed up. I decided to leave it here:
ru.stackoverflow.com/questions/383643
I solved this issue the next day, for which I thank comrade Alexander, who pointed me in which direction to dig. Then I dug up all the information, did everything, and posted the solution on another forum, where I also asked this question. In general, if anyone needs - you can read. :)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question