-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathaframe-multi-video-component-component.min.js
1 lines (1 loc) · 2.09 KB
/
aframe-multi-video-component-component.min.js
1
!function(e){function t(n){if(i[n])return i[n].exports;var o=i[n]={exports:{},id:n,loaded:!1};return e[n].call(o.exports,o,o.exports,t),o.loaded=!0,o.exports}var i={};return t.m=e,t.c=i,t.p="",t(0)}([function(e,t){if("undefined"==typeof AFRAME)throw new Error("Component attempted to register before AFRAME was available.");AFRAME.registerComponent("aframe-multi-video-component",{dependencies:["geometry"],schema:{src:{type:"string"},time:{type:"number",default:0},duration:{type:"number"},volume:{type:"number",default:.5},autoplay:{type:"boolean",default:!1}},multiple:!1,video:null,combined_time:null,init:function(){this.src=this.data.src.replace("#",""),this.time=this.data.time,this.duration=this.data.duration,this.volume=this.data.volume,this.autoplay=this.data.autoplay;var e=this.el,t=(this.el.sceneEl.object3D,this.time,document.getElementById(this.src));this.video=t.cloneNode(!0);var i=new THREE.PlaneGeometry(4,2,1),n=new THREE.VideoTexture(this.video);n.minFilter=THREE.LinearFilter,n.magFilter=THREE.LinearFilter,n.format=THREE.RGBFormat;var o=new THREE.MeshBasicMaterial({map:n,side:THREE.DoubleSide}),a=new THREE.Mesh(i,o);this.video.currentTime=this.time,this.video.volume=this.volume,1==this.autoplay&&this.video.play(),e.setObject3D("mesh",a),this.updateCombinedTime();var r=this.ontimeupdateHandler.bind(this);this.video.ontimeupdate=r,this.vid_length=0;var d=this.videoReadyIntervalHandler.bind(this);this.i=setInterval(d,200)},ontimeupdateHandler:function(){this.timeTracking()},videoReadyIntervalHandler:function(){var e=this.video,t=this.i;e.readyState>0&&(this.setVideoLength(e.duration),clearInterval(t))},setVideoLength:function(e){var t=this.el.getAttribute("aframe-multi-video-component"),i=t.duration;null!=typeof i&&0!=i||(this.el.setAttribute("aframe-multi-video-component.duration",e),this.vid_length=e,this.duration=e,this.updateCombinedTime())},timeTracking:function(){this.video.currentTime>this.combined_time&&(this.video.currentTime=this.time)},updateCombinedTime:function(){this.combined_time=this.time+this.duration},update:function(e){},remove:function(){},pause:function(){},play:function(){}})}]);