html video preload

const video = document.querySelector('video');

const mediaSource = new MediaSource();
video.src = URL.createObjectURL(mediaSource);
  
mediaSource.addEventListener('sourceopen', function() {
  URL.revokeObjectURL(video.src);

  mediaSource.addSourceBuffer('video/webm; codecs="vp9"');

  log('Fetching video init segment...');
  fetchAndAppendSegment('bytes=0-299');
}, { once: true });

function onSetInfiniteDurationButtonClick() {
  log('User clicked "mediaSource.duration = +Infinity" button');
  // Makes video behave like a live stream.
  mediaSource.duration = +Infinity;
  logMediaInfo();
}

function onFetchAndAppend3To6MediaButtonClick() {
  log('Fetching video segment that starts at 3 seconds...');
  fetchAndAppendSegment('bytes=567140-1196488');
}

function onSetLiveSeekableRangeButtonClick(event) {
  const re = /mediaSource\.setLiveSeekableRange\((\d+), (\d+)\)/;
  const start = Number(re.exec(event.target.textContent)[1]);
  const end = Number(re.exec(event.target.textContent)[2]);
  log(`User clicked "mediaSource.setLiveSeekableRange(${start}, ${end})" button`);
  mediaSource.setLiveSeekableRange(start, end);
  logMediaInfo();
}

function onClearLiveSeekableRangeButtonClick() {
  log('User clicked "mediaSource.clearLiveSeekableRange()" button');
  mediaSource.clearLiveSeekableRange();
  logMediaInfo();
}

function onRemoveMediaSegmentButtonClick() {
  const sourceBuffer = mediaSource.sourceBuffers[0];

  log('User clicked "sourceBuffer.remove(3, 6)" button');
  sourceBuffer.remove(3 /* start */, 6 /* end*/);
  sourceBuffer.addEventListener('updateend', function() {
    logMediaInfo();
  }, { once: true });
}

function onSetFiniteDurationButtonClick() {
  log('User clicked "mediaSource.duration = 6" button');
  mediaSource.duration = 6;
  logMediaInfo();
}

function onEndOfStreamButtonClick() {
  log('User clicked "mediaSource.endOfStream()" button');
  mediaSource.endOfStream();
  mediaSource.addEventListener('sourceended', function() {
    logMediaInfo();
  }, { once: true });
}

/* Utils */

function fetchAndAppendSegment(range) {
  const videoUrl = 'https://storage.googleapis.com/media-session/sample.webm';
  const sourceBuffer = mediaSource.sourceBuffers[0];

  fetch(videoUrl, { headers: { range } })
  .then(response => response.arrayBuffer())
  .then(data => {
    sourceBuffer.appendBuffer(data);
    sourceBuffer.addEventListener('updateend', function() {
      logMediaInfo();
    }, { once: true });
  });
}

function logMediaInfo() {
  log(`> Seekable time ranges: ${timeRangesToString(video.seekable)}`);
  log(`> Buffered time ranges: ${timeRangesToString(video.buffered)}`);
  log(`> MediaSource duration: ${mediaSource.duration}`);
  log('');
}

function timeRangesToString(ranges) {
  var s = "{";
  for (var i = 0; i < ranges.length; ++i) {
    s += " [" + ranges.start(i).toFixed(3) + ", " + ranges.end(i).toFixed(3) + ")";
  }
  return s + " }";
}

Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
preload on html5 video preload video's html js preload in video tag video html tag preload preload in html video video preload in html preload a html video html5 preload video preload attribute html video html video preloader html video controls preload html5 video player preload html video preload attribute play a video as a preloader html preload html5 video preload videos html preloading video html5 preload video in html5 preload entire video html5 html video preload entire video html video preload image html5 preload entire video video tag preload html video.loading=&quot;&quot; video insert in html preload css preloader video. html video preload=auto not working how to play video in preload html preload video tag html how to make videos load when clicking html5 video force preload attribute preload video video html5 preload preload in html vvideo preload auto in video tag video autoload video element preload video preload metadata preload= metadata how to upload a video to html tell html source to play video on page load Large Video Not loaded in Video Tag HTml Not load the Larg Video in video tag in html preload attribute of vidio tag html preloader video preload tag in html5 video as preload to the website preload=&quot;none&quot; html how to load video content first in hmtl how to preload videos in html preload video for header background preload video html5 before html preload vidoe for div preload: none html preload: none css html 5 video preload how to load video based on browser html5 video preload none tag video on loaded preload options html html video tag no preload video tag preload video preload none how to stop preload of video preload webvideo preload=&quot;none&quot; for html videos video before loading with skip of website in html preload video html htmls5 preload video preload load html5 video after page load css video preload video play on click when preload false preload video video preload=metadata react video preload=metadata video preload attribute react html video preload react html5 video preload support how to preload a mp4 video in html5 how to preload a mp4 video in video preloader in jquery preload attribute of video tag preload html video preload none video.preload preload=&quot;auto&quot; how to preload video in reactjs html video tag how to make video preload css preload=&quot;metadata&quot; video laod smaller by metabate lhtml preload in html preload metadata vs auto preload none html5 preload video html5 javascript html video tag preload preloader for video screen css preloader for video screen html async video tag in html html load video template data preload none html5 video html video tag buffer size video perload get meta &lt;video class='video-item' preload=&quot;metadata&quot; HTML Which is true of the following code snippet? &lt;video controls=&quot;controls&quot; preload=&quot;metadata&quot;&gt; &lt;source src=&quot;clip1.mp4&quot; type=&quot;video/mp4&quot; /&gt; &lt;/video&gt; video preload html5 html video auto load play video when it loads html preload video example how to turn preload off and autoplay html5 video in bootstrap modal how to autoplay html video with preload none how to autoplay html5 video with preload none preload_metadata html video preload auto video preload attribute video html preload preload attribute html5 video preload video attribute preload html video preload options html iframe vs video preload video html5 html video preload video preload html html preload video
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source