|
58 | 58 | }
|
59 | 59 | CANVAS {
|
60 | 60 | background-color: gray;
|
| 61 | + display: block; |
61 | 62 | }
|
62 | 63 | #advanced {
|
63 | 64 | color: gray;
|
|
82 | 83 | }
|
83 | 84 | img {
|
84 | 85 | border: solid black 2px;
|
| 86 | +} |
| 87 | + .fulldialog { |
| 88 | + display: flex; |
| 89 | + display: -webkit-flex; |
| 90 | + flex-flow: column; |
| 91 | + -webkit-flex-flow: column; |
| 92 | + justify-content: center; |
| 93 | + align-content: center; |
| 94 | + align-items: center; |
| 95 | + -webkit-justify-content: center; |
| 96 | + -webkit-align-content: center; |
| 97 | + -webkit-align-items: center; |
| 98 | + |
| 99 | + position: absolute; |
| 100 | + z-index: 10; |
| 101 | + left: 0; |
| 102 | + top: 0; |
| 103 | + width: 100%; |
| 104 | + height: 100%; |
| 105 | + background-color: rgba(0,0,0,0.8); |
| 106 | + } |
| 107 | + .fulldialog > * { |
| 108 | + padding: 1em; |
| 109 | + background-color: rgba(0,0,0,0.8); |
| 110 | + border: 1px solid #666; |
| 111 | + border-radius: 0.5em; |
| 112 | + } |
| 113 | +#start { |
| 114 | + background-color: rgba(0,0,0,0.0); |
| 115 | +} |
| 116 | +#start>div { |
| 117 | + text-align: center; |
| 118 | +} |
| 119 | +#start>div>div { |
| 120 | + text-align: left; |
| 121 | + color: red; |
| 122 | + font-weight: bold; |
| 123 | +} |
| 124 | +#start img { |
| 125 | + display: inline-block; |
| 126 | + width: 10em; |
| 127 | + height: 10em; |
| 128 | +} |
| 129 | +#start:after { |
| 130 | + box-shadow: inset 0 0 10em rgba(0,0,0,0.9); |
| 131 | + position: absolute; |
| 132 | + top: 0; |
| 133 | + left: 0; |
| 134 | + width: 100%; |
| 135 | + height: 100%; |
| 136 | + z-index: 12; |
| 137 | + content: ""; |
85 | 138 | }
|
86 | 139 | </style>
|
87 | 140 | </head>
|
|
99 | 152 | <div id="viewContainer">
|
100 | 153 | <canvas id="canvas" width="1024" height="1024" style="width: 100%; height: 100%;"></canvas>
|
101 | 154 | </div>
|
102 |
| - <div style="display:none;"> |
103 |
| - <video id="vid"> |
| 155 | +<div id="start" class="fulldialog"> |
| 156 | + <div> |
| 157 | + <img src="../video/start.svg" /> |
| 158 | + </div> |
| 159 | +</div> |
| 160 | +<div style="display:none;"> |
| 161 | + <video id="vid" src="sample-video.mp4"> |
104 | 162 | <!--
|
105 | 163 | <source src="http://studio.html5rocks.com/samples/video-player/chromeicon.mp4" type='video/mp4; codecs="avc1.42E01E, mp4a.40.2"' />
|
106 | 164 | <source src="http://videos-cdn.mozilla.net/firefox/3.6/getpersonas.ogv" type='video/ogg; codecs="theora, vorbis"' />
|
107 | 165 | <source src="sample-video.theora.ogv" type='video/ogg; codecs="theora, vorbis"' />
|
108 |
| - --> |
109 | 166 | <source src="sample-video.theora.ogv" type='video/ogg; codecs="theora, vorbis"' />
|
110 | 167 | <source src="sample-video.webmvp8.webm" type='video/webm; codecs="vp8, vorbis"' />
|
111 | 168 | <source src="sample-video.mp4" type='video/mp4; codecs="avc1.42E01E, mp4a.40.2"' />
|
| 169 | + --> |
112 | 170 | </video>
|
113 |
| - </div> |
| 171 | +</div> |
114 | 172 | </body>
|
115 | 173 | <!-- ===[ basic ]============================================== -->
|
116 | 174 | <script id="basicVertexShader" type="text/something-not-javascript">
|
|
189 | 247 | tdl.require('tdl.textures');
|
190 | 248 | tdl.require('tdl.webgl');
|
191 | 249 |
|
| 250 | +var isiOS = window.navigator.userAgent.match(/iPhone|iPad|iPod/i); |
| 251 | + |
192 | 252 | // globals
|
193 | 253 | var gl; // the gl context.
|
194 | 254 | var canvas; // the canvas
|
|
477 | 537 |
|
478 | 538 | var startTime = 0; // 196
|
479 | 539 | var copyVideo = false;
|
| 540 | + var setVideo = false; |
480 | 541 | var madeVideoTexture = false;
|
| 542 | + var audio; |
481 | 543 | var video = document.getElementById("vid");
|
482 |
| - video.addEventListener("playing", function() { |
483 |
| - copyVideo = true; |
484 |
| - }, true); |
485 |
| - video.addEventListener("ended", function() { |
486 |
| - video.currentTime = startTime; video.play(); |
487 |
| - }, true); |
488 |
| - video.addEventListener("error", function() { |
489 |
| - tdl.log("could not play video"); |
490 |
| - }, true); |
491 |
| - video.volume = 0; |
492 |
| - video.play(); |
| 544 | + |
| 545 | + { |
| 546 | + // we need to start inside a touch event |
| 547 | + var start = document.querySelector("#start"); |
| 548 | + var once = false; |
| 549 | + |
| 550 | + start.addEventListener('touchstart', onTouch); |
| 551 | + start.addEventListener('mousedown', onTouch); |
| 552 | + function onTouch() { |
| 553 | + if (once) { |
| 554 | + return; |
| 555 | + } |
| 556 | + once = true; |
| 557 | + start.style.display = "none"; |
| 558 | + video.addEventListener("playing", function() { |
| 559 | + copyVideo = true; |
| 560 | + }, true); |
| 561 | + video.addEventListener("ended", function() { |
| 562 | + video.currentTime = startTime; video.play(); |
| 563 | + }, true); |
| 564 | + video.addEventListener("error", function(e) { |
| 565 | + console.error("could not play video" + e); |
| 566 | + }, true); |
| 567 | + video.volume = 0; |
| 568 | + if (isiOS) { |
| 569 | + // iOS9 doesn't let us play video without going fullscreen :( |
| 570 | + // so a workaround, which I'm sure Apple will *fix* as in "make it not work" |
| 571 | + // is to create an audio tag using the same video |
| 572 | + // play the audio. DON'T PLAY THE VIDEO. Set the video's currentTime to match |
| 573 | + // the audio. I can't believe this works |
| 574 | + audio = document.createElement("audio"); |
| 575 | + audio.volume = 0; |
| 576 | + audio.src = "sample-video.mp4"; |
| 577 | + audio.addEventListener("ended", function() { |
| 578 | + audio.currentTime = 0; |
| 579 | + audio.play(); |
| 580 | + }); |
| 581 | + audio.play(); |
| 582 | + video.addEventListener("canplaythrough", function() { |
| 583 | + setVideo = true; |
| 584 | + }, true); |
| 585 | + video.load(); |
| 586 | + } else { |
| 587 | + video.play(); |
| 588 | + } |
| 589 | + } |
| 590 | + } |
493 | 591 |
|
494 | 592 | var showRT = false;
|
495 | 593 | document.addEventListener('keypress', function(event) {
|
|
549 | 647 | target[1] = g_targetHeight;
|
550 | 648 | target[2] = Math.cos(g_eyeClock + Math.PI) * g_targetRadius;
|
551 | 649 |
|
552 |
| - if (copyVideo) { |
553 |
| - if (video.currentTime < startTime) { |
554 |
| - video.currentTime = startTime; |
| 650 | + if (copyVideo || setVideo) { |
| 651 | + if (setVideo) { |
| 652 | + video.currentTime = audio.currentTime; |
555 | 653 | }
|
556 | 654 | gl.bindTexture(gl.TEXTURE_2D, g_videoTexture.texture);
|
557 | 655 | if (!madeVideoTexture) {
|
|
0 commit comments