so, i've been toying with this for a little bit and i am awful with JS but i feel like I'm really close to figuring it out, so even just being pointed in the right direction would help.
Right now i have audio that plays persistently across page changes via cookies, and that part is working great. however when the song source changes, I would really like the song to start back at 0. (Right now it just keeps playing at the value the cookie currently holds.)
This is what I have so far:
var song = document.getElementsByTagName("audio")[0];
var source = song.currentSrc;
var originalSource = source;
var played = false;
var tillPlayed = getCookie("timePlayed");
function update()
{
if(!played){
if(tillPlayed){
if (source == originalSource){
song.currentTime = tillPlayed;
song.play();
played = true;
}
else {
song.currentTime = 0;
cong.currentTime = tillPlayed;
song.play();
played = true;
}
}
else {
song.play();
played = true;
}
}
else {
setCookie('timePlayed', song.currentTime);
}
}
setInterval(update,0);
And it just makes the song not play at all.
It looks like it should be correct, and i'm just at a loss at this point as to why it's not working.
Anyone have any tips on getting it to function?
EDIT: Ive moved the extra code into the original function, this is what I have at this point. It's still not working, the music will play again, but it doesn't reset the cookie.
The cookie does function as it should, I am just trying to change it