title: m3u8 360 virtual reality video with Three js
body: <p>Is there a way to play 360 video with Three js coming from m3u8 file?</p>
  <p>I found a similar question here but no answer:  <a href="https://github.com/mrdoob/three.js/issues/8216" rel="nofollow noreferrer">https://github.com/mrdoob/three.js/issues/8216</a></p>
  <p><a href="https://threejs.org/examples/webgl_video_panorama_equirectangular.html" rel="nofollow noreferrer">https://threejs.org/examples/webgl_video_panorama_equirectangular.html</a></p>
  <p>I have used the code from thee website for playing 360 video and this work fine when normal mp4 video url is used but when I try to include m3u8 then it fails with error.MEDIA_ERR_SRC_NOT_SUPPORTED:</p>
  <pre><code>  The video could not be loaded, either because the server or network failed or because the format is not supported.
  </code></pre>
  <p>Here is the code:</p>
  <pre><code>&lt;video id=&quot;video&quot; width=960 height=540 style=&quot;display:none&quot;&gt;
    &lt;source src=&quot;https://bitmovin.com/player-content/playhouse-vr/m3u8s/105560.m3u8&quot; type=&quot;application/x-mpegURL&quot;&gt;
  &lt;/video&gt;
  
  
  
          var camera, scene, renderer;
  
          var isUserInteracting = false,
              lon = 0, lat = 0,
              phi = 0, theta = 0,
              distance = 50,
              onPointerDownPointerX = 0,
              onPointerDownPointerY = 0,
              onPointerDownLon = 0,
              onPointerDownLat = 0;
  
          init();
          animate();
  
          function init() {
  
              var container, mesh;
  
              container = document.getElementById( 'container' );
  
              camera = new THREE.PerspectiveCamera( 75, window.innerWidth / window.innerHeight, 1, 1100 );
              camera.target = new THREE.Vector3( 0, 0, 0 );
  
              scene = new THREE.Scene();
  
              var geometry = new THREE.SphereBufferGeometry( 500, 60, 40 );
              // invert the geometry on the x-axis so that all of the faces point inward
              geometry.scale( - 1, 1, 1 );
  
              var video = document.getElementById( 'video' );
              video.play();
  
              var texture = new THREE.VideoTexture( video );
              var material = new THREE.MeshBasicMaterial( { map: texture } );
  
              mesh = new THREE.Mesh( geometry, material );
  
              scene.add( mesh );
  
              renderer = new THREE.WebGLRenderer();
              renderer.setPixelRatio( window.devicePixelRatio );
              renderer.setSize( window.innerWidth, window.innerHeight );
              container.appendChild( renderer.domElement );
  
              document.addEventListener( 'mousedown', onDocumentMouseDown, false );
              document.addEventListener( 'mousemove', onDocumentMouseMove, false );
              document.addEventListener( 'mouseup', onDocumentMouseUp, false );
              document.addEventListener( 'wheel', onDocumentMouseWheel, false );
  
              //
  
              window.addEventListener( 'resize', onWindowResize, false );
  
          }
  
          function onWindowResize() {
  
              camera.aspect = window.innerWidth / window.innerHeight;
              camera.updateProjectionMatrix();
  
              renderer.setSize( window.innerWidth, window.innerHeight );
  
          }
  
          function onDocumentMouseDown( event ) {
  
              event.preventDefault();
  
              isUserInteracting = true;
  
              onPointerDownPointerX = event.clientX;
              onPointerDownPointerY = event.clientY;
  
              onPointerDownLon = lon;
              onPointerDownLat = lat;
  
          }
  
          function onDocumentMouseMove( event ) {
  
              if ( isUserInteracting === true ) {
  
                  lon = ( onPointerDownPointerX - event.clientX ) * 0.1 + onPointerDownLon;
                  lat = ( onPointerDownPointerY - event.clientY ) * 0.1 + onPointerDownLat;
  
              }
  
          }
  
          function onDocumentMouseUp() {
  
              isUserInteracting = false;
  
          }
  
          function onDocumentMouseWheel( event ) {
  
              distance += event.deltaY * 0.05;
  
              distance = THREE.MathUtils.clamp( distance, 1, 50 );
  
          }
  
          function animate() {
  
              requestAnimationFrame( animate );
              update();
  
          }
  
          function update() {
  
              lat = Math.max( - 85, Math.min( 85, lat ) );
              phi = THREE.MathUtils.degToRad( 90 - lat );
              theta = THREE.MathUtils.degToRad( lon );
  
              camera.position.x = distance * Math.sin( phi ) * Math.cos( theta );
              camera.position.y = distance * Math.cos( phi );
              camera.position.z = distance * Math.sin( phi ) * Math.sin( theta );
  
              camera.lookAt( camera.target );
  
              renderer.render( scene, camera );
  
          }
  
      
  </code></pre>
  <p>m3u8 plays on chrome (and some other browsers). I have been using it for years. The problem is in combining m3u8 format with three js</p>
  <p>m3u8 works as can be seen here: <a href="https://hls-js.netlify.app/demo/" rel="nofollow noreferrer">https://hls-js.netlify.app/demo/</a> enter this url : <a href="https://bitmovin.com/player-content/playhouse-vr/m3u8s/105560.m3u8" rel="nofollow noreferrer">https://bitmovin.com/player-content/playhouse-vr/m3u8s/105560.m3u8</a></p>