[% IF audiofile %]
<audio id="audiofileid">
  <source src="[% audiofile | html %]" [% IF audiofile.match("\.wav$") %]type="audio/wav"[% ELSIF audiofile.match("\.mp3$") %]type="audio/mpeg"[% ELSIF audiofile.match("\.ogg$") %]type="audio/ogg"[% END %]>
</audio>
<script>
  var el = document.getElementById("audiofileid");
  if(el) {
    try {
      el.play();
    } catch (error) {
      console.log(error);
    }
  }
  var error = "";
  try {
    if(navigator.getAutoplayPolicy("mediaelement") !== "allowed") {
      error = "cannot play audio file, auto play is disabled by your browser";
    }
  } catch (error) {
    console.log(error);
  }

  if(error != "") {
    if(jQuery("#audiomsg").length > 0) {
      jQuery("#audiomsg").text(error);
    } else {
      thruk_message(1, error);
    }
  }
</script>
[% END %]
