title: Decode a base64 video blob with JavaScript
body: <p>I've made a video encoder that gives output in base64 encoded video.</p>
  
  <p>A video player needs to play the video in the browser.
  My current code doesn't works, I tried it also with responseText and not with the response as a blob.</p>
  
  <p>So the server gets the video and processes it as a base64 string.
  Then the browser needs to decode it and view it as a video, how can I get this done?</p>
  
  <p>My code:</p>
  
  <pre><code>decodeBase64 = function(s) {
      var e={},i,b=0,c,x,l=0,a,r='',w=String.fromCharCode,L=s.length;
      var A="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
      for(i=0;i&lt;64;i++){e[A.charAt(i)]=i;}
      for(x=0;x&lt;L;x++){
          c=e[s.charAt(x)];b=(b&lt;&lt;6)+c;l+=6;
          while(l&gt;=8){((a=(b&gt;&gt;&gt;(l-=8))&amp;0xff)||(x&lt;(L-2)))&amp;&amp;(r+=w(a));}
      }
      return r;
  };
  var xhr = new XMLHttpRequest();
  xhr.open("GET", "video");
  xhr.responseType = "blob";
  xhr.onload = response;
  xhr.send();
  
  function response(e) {
     var URL = window.URL || window.webkitURL;
     var videoUrl = URL.createObjectURL(decodeBase64(this.response));
     document.querySelector("video").src = videoUrl;
  }
  </code></pre>