Skip to content

Commit 7d361da

Browse files
authored
Merge pull request #514 from mozilla/features/video-sync
Support for basic video synchronization
2 parents bedca50 + 50e108f commit 7d361da

File tree

5 files changed

+445
-280
lines changed

5 files changed

+445
-280
lines changed

src/components/image-plus.js

Lines changed: 0 additions & 265 deletions
This file was deleted.

src/components/media-loader.js

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ AFRAME.registerComponent("media-loader", {
1111
init() {
1212
this.onError = this.onError.bind(this);
1313
this.showLoader = this.showLoader.bind(this);
14+
this.clearLoadingTimeout = this.clearLoadingTimeout.bind(this);
1415
},
1516

1617
setShapeAndScale(resize) {
@@ -40,7 +41,8 @@ AFRAME.registerComponent("media-loader", {
4041
onError() {
4142
this.el.removeAttribute("gltf-model-plus");
4243
this.el.removeAttribute("media-pager");
43-
this.el.setAttribute("image-plus", { src: "error" });
44+
this.el.removeAttribute("media-video");
45+
this.el.setAttribute("media-image", { src: "error" });
4446
clearTimeout(this.showLoaderTimeout);
4547
delete this.showLoaderTimeout;
4648
},
@@ -52,6 +54,11 @@ AFRAME.registerComponent("media-loader", {
5254
delete this.showLoaderTimeout;
5355
},
5456

57+
clearLoadingTimeout() {
58+
clearTimeout(this.showLoaderTimeout);
59+
delete this.showLoaderTimeout;
60+
},
61+
5562
async update(oldData) {
5663
try {
5764
const { src, index } = this.data;
@@ -65,18 +72,19 @@ AFRAME.registerComponent("media-loader", {
6572
const { raw, images, contentType } = await resolveMedia(src, false, index);
6673

6774
const isPDF = contentType.startsWith("application/pdf");
68-
if (
69-
contentType.startsWith("image/") ||
70-
contentType.startsWith("video/") ||
71-
contentType.startsWith("audio/") ||
72-
isPDF
73-
) {
75+
if (contentType.startsWith("video/") || contentType.startsWith("audio/")) {
76+
this.el.removeAttribute("gltf-model-plus");
77+
this.el.removeAttribute("media-image");
78+
this.el.addEventListener("video-loaded", this.clearLoadingTimeout, { once: true });
79+
this.el.setAttribute("media-video", { src: raw });
80+
this.el.setAttribute("position-at-box-shape-border", { dirs: ["forward", "back"] });
81+
} else if (contentType.startsWith("image/") || isPDF) {
7482
this.el.removeAttribute("gltf-model-plus");
83+
this.el.removeAttribute("media-video");
7584
this.el.addEventListener(
7685
"image-loaded",
7786
async () => {
78-
clearTimeout(this.showLoaderTimeout);
79-
delete this.showLoaderTimeout;
87+
this.clearLoadingTimeout();
8088
if (isPDF) {
8189
const maxIndex = await fetchMaxContentIndex(src, images.png);
8290
this.el.setAttribute("media-pager", { index, maxIndex });
@@ -91,7 +99,7 @@ AFRAME.registerComponent("media-loader", {
9199
this.el.removeAttribute("media-pager");
92100
}
93101

94-
this.el.setAttribute("image-plus", { src: imageSrc, contentType: imageContentType });
102+
this.el.setAttribute("media-image", { src: imageSrc, contentType: imageContentType });
95103
this.el.setAttribute("position-at-box-shape-border", { dirs: ["forward", "back"] });
96104
} else if (
97105
contentType.includes("application/octet-stream") ||
@@ -100,13 +108,13 @@ AFRAME.registerComponent("media-loader", {
100108
src.endsWith(".gltf") ||
101109
src.endsWith(".glb")
102110
) {
103-
this.el.removeAttribute("image-plus");
111+
this.el.removeAttribute("media-image");
112+
this.el.removeAttribute("media-video");
104113
this.el.removeAttribute("media-pager");
105114
this.el.addEventListener(
106115
"model-loaded",
107116
() => {
108-
clearTimeout(this.showLoaderTimeout);
109-
delete this.showLoaderTimeout;
117+
this.clearLoadingTimeout();
110118
this.setShapeAndScale(this.data.resize);
111119
},
112120
{ once: true }

0 commit comments

Comments
 (0)