I'm a radio presenter and have an mp3 stream of my broadcasts set up to autoplay on my website (I know, I know, just humour me). Using the HTML5 audio tag, I want the audio to autoplay the first time someone visits my site.
However, I want them to be able to check a checkbox with the result that the audio never autoplays for them again unless they uncheck the checkbox.
This checkbox should appear just under the audio player and change the autoplay tag from "true" to "false".
I've seen plugins that will stop autoplay, but can't find any code online to offer the option myself, which just goes to show how many people use autoplay indiscriminately. I would never dream of using it without offering a disable option.
Following some quick research I have put together the following code, but as I am a n00b coder I can't make it work. Where am I going wrong and what is the most elegant solution?
<audio controls autoplay="true"><source src="stream.mp3" type="audio/mp3" </audio>
<input type="checkbox" name="disable-autoplay" value="disable-autoplay" onchange="check(this)" />
function check(that)
if
(that.value === "disable-autoplay")
if ((this).is(':checked')) {
autoplay="no"('checked');
} else {
autoplay="autoplay"('unchecked');
}
Aucun commentaire:
Enregistrer un commentaire