<script>

  window.onVidyardAPI = (vidyardEmbed) => {
    vidyardEmbed.api.addReadyListener((_, player) => {
      const ldTag = setupLdTag();
      document.head.insertAdjacentHTML('beforeend', ldTag)
    },)
  }
  
  function setupLdTag() {
    var player = VidyardV4.players[0];
    var time = player.metadata.length_in_seconds
    var time_minutes = Math.floor(time / 60)
    var time_seconds = time % 60
    var videoUrl = 'https://play.vidyard.com/' + player.uuid
    
    return `
      <script type="application/ld+json">
        {
          "@context": "https://schema.org/",
          "@type": "VideoObject",
          "name": "{{ course.name }}",
          "description": "{{ course.short_description }}",
          "thumbnailUrl": "{{ course.image_url }}",
          "uploadDate": "{{ course.created_at }}",
          "duration": "T${time_minutes}M${time_seconds}S",
          "embedUrl": "${videoUrl}"
        }
      <\/script>`
  }

</script>
