-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsnippet.js
81 lines (72 loc) · 2.55 KB
/
snippet.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// load video before starting AR
const loadVideo = () => {
// load video for video playback and create videoTexture
var video = document.createElement('video')
video.setAttribute('muted' , true)
video.setAttribute('preload', "auto")
video.setAttribute('playsinline', true)
video.muted = true
video.playsinline = true
video.autoplay = false
video.preload = 'auto'
// Don't autoplay
// video.play()
video.oncanplay = () => {
console.log('video can play')
}
video.oncanplaythrough = () => {
console.log('can play through')
// Open the camera and start running the camera run loop.
XR8.run({canvas: document.getElementById('camerafeed')})
}
video.addEventListener('error', (e) => {
console.error(`Error loading: ${videoSrc}`, e);
});
video.loop = true
const texture = new THREE.VideoTexture(video)
texture.minFilter = THREE.LinearFilter
texture.magFilter = THREE.LinearFilter
texture.format = THREE.RGBFormat
texture.crossOrigin = 'anonymous'
videoObj = new THREE.Mesh(
new THREE.PlaneGeometry(0.75, 1),
new THREE.MeshBasicMaterial({map: texture})
)
// Hide video until image target is detected.
videoObj.visible = false
scene.add(videoObj)
video.load()
}
// Video failover
this.video.play().then(() => {
console.log("playing")
}).catch(e => {
console.log(e)
this.video.muted = true
this.video.play().catch(e => console.log(e))
})
// Places content over image target
const updateTarget = ({detail}) => {
// When the image target named 'video-target' is detected, play video.
// This string must match the name of the image target uploaded to 8th Wall.
if (detail.name === 'video-target') {
videoObj.position.copy(detail.position)
videoObj.quaternion.copy(detail.rotation)
videoObj.scale.set(detail.scale, detail.scale, detail.scale)
videoObj.visible = true
video.play()
}
}
const playButton = document.getElementById('unmuteButton')
const playButtonImg = document.getElementById('unmuteButtonImg')
playButton.style.display = 'inline'
playButton.addEventListener('click', () => {
if(this.video.muted) {
this.videoOverlay.muted = false;
playButtonImg.src = "./round_volume_up_white_36dp.png"
} else {
this.video.muted = true;
playButtonImg.src = "./round_volume_off_white_36dp.png"
}
})
<div id="unmuteButton" style="position:absolute;top:10px;right:10px;z-index: 99;"><img id="unmuteButtonImg" src="./round_volume_off_white_36dp.png" width="35px" height="35px"></div>