Three.js检测视频已准备好在移动设备上播放

时间:2016-03-03 23:28:59

标签: javascript jquery video three.js html5-video

我在球体纹理上使用视频,并尝试仅在视频加载后显示球体。在移动设备上,我在视频加载时总会得到黑色球体,几秒钟后视频开始播放。

无论如何都要检测球体上的视频是否真的在播放之前播放?

      if(!video){
        video = document.createElement( 'video' );
        video.width = 2048;
        video.height = 1024;
        //video.autoplay = true;
        video.loop = true;
        video.crossOrigin = '';
        video.preload = 'auto';
   }

// video.src = cdnPrefix + "/"+ sceneObject.video;
    video.src = cdnPrefix + "/uploads/out3_8.mp4";





    geometry = new THREE.SphereGeometry( 500, 60, 40 );
    var texture = new THREE.VideoTexture( video );
    texture.minFilter = THREE.LinearFilter;

    var material   = new THREE.MeshBasicMaterial( { map : texture } );
    // material.side = THREE.BackSide;

    panoVideoMesh = new THREE.Mesh( geometry, material );
    panoVideoMesh.scale.x = -1;
    panoVideoMesh.rotation.y = Math.PI / 2;

    if(!isMobile)
        panoVideoPlay();
    else
        window.addEventListener('touchstart', function videoStart() {
            panoVideoPlay();
            this.removeEventListener('touchstart', videoStart);
        });

    scene.add( panoVideoMesh );
    panoVideoMesh.visible = false;

}

 function panoVideoPlay(){
  video.load();

    video.addEventListener('canplay',function(){
        scene.remove(box);
        panoVideoMesh.visible = true;
        video.play();
});

}

1 个答案:

答案 0 :(得分:0)

我想你可以过得去 video.readyState是真还是假

Html 5中还有许多其他有用的视频标签功能和属性,你可以在这里查看http://www.w3schools.com/tags/ref_av_dom.asp