0

I have a video playing as a banner that uses javascript. I need to add a caption track, but just adding the caption code to the video section doesn't work. I tried..

  • Adding the vtt caption code within the video code, but it doesn't work.

  • I added <track label="English" kind="subtitles" srclang="en" src="/media/Images/Home2018/Banner/BannerVideo3.vtt"> default within the video tags, but this doesn't work.

I think the JS needs to be updated somehow to include the captions track.

I Below is my code:

    <video id="BannerVideo3" class="Banner" muted playsinline loop oncanplaythrough="playBannerVideo3()" controls autoplay muted playsinline>
</video>

<script>
function playBannerVideo3()
{
  var videoElement = document.getElementById('BannerVideo3');
  try 
  {
    videoElement.play();
  }
  catch(err) {}
}

var basePosterURL = '/media/Images/Home2018/Banner/BannerVideo3.jpg';
var baseVideoURL = '/media/Images/Home2018/Banner/BannerVideo3.mp4';

function getNameForCurrentWidth()
{
  var bodyWidth = document.body.clientWidth; // $('body').width();
  if (bodyWidth <= 767)
    return '_Phone';

  if (bodyWidth <= 990)
    return '_Tablet';

  return ''; // Desktop
}

var loadedWidthName;
function loadBannerVideo3(posterOnly)
{
  var newWidthName = getNameForCurrentWidth();
  if(newWidthName == loadedWidthName)
    return;

  loadedWidthName = newWidthName;
  var videoElement = document.getElementById('BannerVideo3');

  if (!videoElement.paused)
    videoElement.pause();

  videoElement.src = '';
  videoElement.poster = addToFilename(basePosterURL, loadedWidthName);

  if (posterOnly == true)
    return;

  setBannerVideoSrc(loadedWidthName);
}

function setBannerVideo3Src(newWidthName)
{
  // don't play video if in design or edit modes
  if( $('body.DesignMode').length == 1 ||  $('body.EditMode').length == 1)
    return;

  var videoElement = document.getElementById('BannerVideo3');
  videoElement.src = addToFilename(baseVideoURL, newWidthName);
  videoElement.load();
}

// load poster as soon as possible
$(function() // document.ready
{
  loadBannerVideo3(true);
});

  // load and play video after everything else loads
$(window).on('load',function()
{
  setBannerVideo3Src(loadedWidthName);
});

var resizeTimeout;
$(window).resize(function()
{ 
  clearTimeout(resizeTimeout);
  resizeTimeout = setTimeout(resizeEnd, 200);   
});
function resizeEnd()
{
  loadBannerVideo();
}
</script>
VC.One
  • 14,790
  • 4
  • 25
  • 57
  • **(1)** What browser version did you test the `` code on? Asking incase it doesn't support that. **(2)** Share a link to the VTT for testing purposes (either direct link or share via some file download site like Dropbox etc)... – VC.One Jul 14 '21 at 18:27
  • Chrome and Firefox. – DancingCucumber Jul 14 '21 at 21:12

0 Answers0