Skip to content

Commit f5bb186

Browse files
greggmanphemavax
authored andcommitted
fixes for video, iOS no longer works
1 parent 6d55df0 commit f5bb186

File tree

2 files changed

+129
-28
lines changed

2 files changed

+129
-28
lines changed

color-adjust/color-adjust.html

Lines changed: 116 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
}
5959
CANVAS {
6060
background-color: gray;
61+
display: block;
6162
}
6263
#advanced {
6364
color: gray;
@@ -82,6 +83,58 @@
8283
}
8384
img {
8485
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: "";
85138
}
86139
</style>
87140
</head>
@@ -99,18 +152,23 @@
99152
<div id="viewContainer">
100153
<canvas id="canvas" width="1024" height="1024" style="width: 100%; height: 100%;"></canvas>
101154
</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">
104162
<!--
105163
<source src="http://studio.html5rocks.com/samples/video-player/chromeicon.mp4" type='video/mp4; codecs="avc1.42E01E, mp4a.40.2"' />
106164
<source src="http://videos-cdn.mozilla.net/firefox/3.6/getpersonas.ogv" type='video/ogg; codecs="theora, vorbis"' />
107165
<source src="sample-video.theora.ogv" type='video/ogg; codecs="theora, vorbis"' />
108-
-->
109166
<source src="sample-video.theora.ogv" type='video/ogg; codecs="theora, vorbis"' />
110167
<source src="sample-video.webmvp8.webm" type='video/webm; codecs="vp8, vorbis"' />
111168
<source src="sample-video.mp4" type='video/mp4; codecs="avc1.42E01E, mp4a.40.2"' />
169+
-->
112170
</video>
113-
</div>
171+
</div>
114172
</body>
115173
<!-- ===[ basic ]============================================== -->
116174
<script id="basicVertexShader" type="text/something-not-javascript">
@@ -189,6 +247,8 @@
189247
tdl.require('tdl.textures');
190248
tdl.require('tdl.webgl');
191249

250+
var isiOS = window.navigator.userAgent.match(/iPhone|iPad|iPod/i);
251+
192252
// globals
193253
var gl; // the gl context.
194254
var canvas; // the canvas
@@ -477,19 +537,57 @@
477537

478538
var startTime = 0; // 196
479539
var copyVideo = false;
540+
var setVideo = false;
480541
var madeVideoTexture = false;
542+
var audio;
481543
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+
}
493591

494592
var showRT = false;
495593
document.addEventListener('keypress', function(event) {
@@ -549,9 +647,9 @@
549647
target[1] = g_targetHeight;
550648
target[2] = Math.cos(g_eyeClock + Math.PI) * g_targetRadius;
551649

552-
if (copyVideo) {
553-
if (video.currentTime < startTime) {
554-
video.currentTime = startTime;
650+
if (copyVideo || setVideo) {
651+
if (setVideo) {
652+
video.currentTime = audio.currentTime;
555653
}
556654
gl.bindTexture(gl.TEXTURE_2D, g_videoTexture.texture);
557655
if (!madeVideoTexture) {

video/video.html

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@
9494
<source src="../color-adjust/sample-video.theora.ogv" type='video/ogg; codecs="theora, vorbis"' />
9595
<source src="../color-adjust/sample-video.webmvp8.webm" type='video/webm; codecs="vp8, vorbis"' />
9696
</video>
97-
<div id="start" class="fulldialog" style="display: none;">
97+
<div id="start" class="fulldialog">
9898
<div>
9999
<img src="start.svg" />
100100
</div>
@@ -170,7 +170,6 @@
170170
<script src="../js/twgl-full.min.js"></script>
171171
<script>
172172
"use strict";
173-
var isMobile = window.navigator.userAgent.match(/Android|iPhone|iPad|iPod|Windows Phone/i);
174173
var isiOS = window.navigator.userAgent.match(/iPhone|iPad|iPod/i);
175174
twgl.setDefaults({attribPrefix: "a_"});
176175
var m4 = twgl.m4;
@@ -259,14 +258,18 @@
259258
console.log("could not play video");
260259
}, true);
261260

262-
if (!isMobile) {
263-
// If it's desktop we can start the video automaically
264-
video.play();
265-
} else {
266-
// otherwise we need to start inside a touch event
261+
{
262+
// we need to start inside a touch event
267263
var start = document.querySelector("#start");
268-
start.style.display = "";
269-
start.addEventListener('touchstart', function() {
264+
var once = false;
265+
266+
start.addEventListener('touchstart', onTouch);
267+
start.addEventListener('mousedown', onTouch);
268+
function onTouch() {
269+
if (once) {
270+
return;
271+
}
272+
once = true;
270273
start.style.display = "none";
271274
if (isiOS) {
272275
// iOS9 doesn't let us play video without going fullscreen :(
@@ -288,7 +291,7 @@
288291
} else {
289292
video.play();
290293
}
291-
});
294+
}
292295
}
293296

294297
function render(time) {

0 commit comments

Comments
 (0)