@@ -55,21 +55,28 @@ class VideoTextureExample extends Example {
55
55
addressV : pc . ADDRESS_CLAMP_TO_EDGE
56
56
} ) ;
57
57
58
- // Grab our HTML element with the video
58
+ // Create our HTML element with the video
59
59
const video : HTMLVideoElement = document . createElement ( 'video' ) ;
60
- video . setAttribute ( 'autoplay' , 'true' ) ;
61
- video . setAttribute ( 'loop' , 'true' ) ;
62
- video . setAttribute ( 'muted' , 'true' ) ;
63
- video . setAttribute ( 'playsinline' , 'true' ) ;
64
- video . setAttribute ( 'crossorigin' , 'anonymous' ) ;
65
- video . setAttribute ( 'style' , 'display:none' ) ;
66
- video . setAttribute ( 'id' , 'vid' ) ;
67
- const videoSource : HTMLSourceElement = document . createElement ( 'source' ) ;
68
- videoSource . setAttribute ( 'src' , 'static/assets/video/SampleVideo_1280x720_1mb.mp4' ) ;
69
- videoSource . setAttribute ( 'type' , 'video/mp4' ) ;
70
- video . append ( videoSource ) ;
71
- document . body . append ( 'video' ) ;
72
- video . addEventListener ( 'canplay' , function ( ) {
60
+ video . id = 'vid' ;
61
+ video . loop = true ;
62
+
63
+ // Muted so that we can autoplay
64
+ video . muted = true ;
65
+ video . autoplay = true ;
66
+
67
+ // Inline needed for iOS otherwise it plays at fullscreen
68
+ video . playsInline = true ;
69
+
70
+ video . crossOrigin = "anonymous" ;
71
+
72
+ // Make sure that the video is in view on the page otherwise it doesn't
73
+ // load on some browsers, especially mobile
74
+ video . setAttribute ( 'style' , 'display: block; width: 1px; height: 1px; position: absolute; opacity: 0; z-index: -1000; top: 0px; pointer-events: none' ) ;
75
+
76
+ video . src = 'static/assets/video/SampleVideo_1280x720_1mb.mp4' ;
77
+ document . body . append ( video ) ;
78
+
79
+ video . addEventListener ( 'canplaythrough' , function ( ) {
73
80
videoTexture . setSource ( video ) ;
74
81
} ) ;
75
82
@@ -87,7 +94,6 @@ class VideoTextureExample extends Example {
87
94
entity . render . meshInstances [ 1 ] . material = material ;
88
95
89
96
video . load ( ) ;
90
- // video.play();
91
97
92
98
const mouse = new pc . Mouse ( document . body ) ;
93
99
mouse . on ( 'mousedown' , function ( event ) {
0 commit comments