Jump to content

HTML Video Caching


andyhill

Recommended Posts

Searching the web I found this code for implementing video caching:-

        '    <script>'+
        '      // -- Create a MediaSource and attach it to the video'+
        '      const videoTag = document.getElementById("MyVideoTag");'+
        '      const myMediaSource = new MediaSource();'+
        '      const url = URL.createObjectURL(myMediaSource);'+
        '      videoTag.src = url;'+
        '      // 1. add source buffers'+
        '      const audioSourceBuffer = myMediaSource.addSourceBuffer(''audio/mp4; codecs="mp4a.40.2"'');'+
        '      const videoSourceBuffer = myMediaSource.addSourceBuffer(''video/mp4; codecs="avc1.64001e"'');'+
        '      // 2. download and add our audio/video to the SourceBuffers for the audio SourceBuffer'+
        '      fetch("https://mydomain.com/audio.mp4").then (function(response)'+
        '        {'+
        '          // The data has to be a JavaScript ArrayBuffer'+
        '          return response.arrayBuffer();'+
        '        }'+
        '      ).then (function(audioData) '+
        '        {'+
        '          audioSourceBuffer.appendBuffer(audioData);'+
        '        }'+
        '      );'+
        '      // the same for the video SourceBuffer'+
        '      fetch("https://mydomain.com/video.mp4").then (function(response)'+
        '        {'+
        '          // The data has to be a JavaScript ArrayBuffer'+
        '          return response.arrayBuffer();'+
        '        }'+
        '      ).then (function(videoData)'+
        '        {'+
        '          videoSourceBuffer.appendBuffer(videoData);'+
        '        }'+
        '      );'+
        '    </script>'+

I have added this script to the HtmlFrame that contains the video tag with the id="MyVideoTag" and ask if any other code is required to activate this javascript caching ?

Thanks in advance

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...