-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
107 lines (100 loc) · 3.65 KB
/
main.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
window.onload = function () {
window.AudioContext = window.AudioContext || window.webkitAudioContext;
audioContext = new AudioContext();
// Older browsers might not implement mediaDevices at all, so we set an empty object first
if (navigator.mediaDevices === undefined) {
navigator.mediaDevices = {};
}
// Some browsers partially implement mediaDevices. We can't just assign an object
// with getUserMedia as it would overwrite existing properties.
// Here, we will just add the getUserMedia property if it's missing.
if (navigator.mediaDevices.getUserMedia === undefined) {
navigator.mediaDevices.getUserMedia = function (constraints) {
// First get ahold of the legacy getUserMedia, if present
var getUserMedia =
navigator.getUserMedia ||
navigator.webkitGetUserMedia ||
navigator.mozGetUserMedia;
// Some browsers just don't implement it - return a rejected promise with an error
// to keep a consistent interface
if (!getUserMedia) {
return Promise.reject(
new Error("getUserMedia is not implemented in this browser")
);
}
// Otherwise, wrap the call to the old navigator.getUserMedia with a Promise
return new Promise(function (resolve, reject) {
getUserMedia.call(navigator, constraints, resolve, reject);
});
};
}
navigator.mediaDevices
.getUserMedia({ audio: true, video: false })
.then(gotStream)
.catch(didntGetStream);
};
function chromeMicPermission() {
audioContext.resume().then(() => {
console.log("Playback resumed successfully");
});
}
function didntGetStream(error) {
alert(`Stream genaration failed: ${error} on ${window.navigator.userAgent}`);
}
var mediaStreamSource = null;
function gotStream(stream) {
// Create an AudioNode from the stream.
mediaStreamSource = audioContext.createMediaStreamSource(stream);
// Create a new volume meter and connect it.
meter = createAudioMeter(audioContext);
mediaStreamSource.connect(meter);
}
// Set video from input source to frame
function setVideo() {
if (!document.querySelector("#vimeo-button").classList.contains("disabled")) {
var options = {
// get the digits from the URL representing the ID
id: videoinput.value.match(/(\d)\w+/g),
loop: true,
};
var player = new Vimeo.Player("vimeo-video", options);
player.on("play", function () {
console.log("played the video!");
});
} else if (
!document.querySelector("#file-button").classList.contains("disabled")
) {
const videoFile = document.querySelector(
'.wrapper .content .step .concept [type="file"]'
).files[0];
document
.querySelector("#html-video")
.setAttribute("src", URL.createObjectURL(videoFile));
} else {
throw new Error("Detected strange state. No feasible concept is selected.");
}
}
// Stops the video on current frame
function stopVideo() {
let player;
if (!document.querySelector("#vimeo-button").classList.contains("disabled")) {
var iframe = document.querySelector("iframe");
player = new Vimeo.Player(iframe);
} else if (
!document.querySelector("#file-button").classList.contains("disabled")
) {
player = document.querySelector("#html-video");
} else {
throw new Error("Detected strange state. No feasible concept selected.");
}
player.pause();
const pauseInSeconds = document.querySelector("#pause-seconds").value;
if (pauseInSeconds) {
setTimeout(() => player.play(), parseInt(pauseInSeconds) * 1000);
}
}
function onVideoConceptChange(event) {
document
.querySelectorAll(".video-concept-button, .concept")
.forEach((node) => node.classList.toggle("disabled"));
}