Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/extensions/media-preview/media/videoPreview.js
3292 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
// @ts-check
6
"use strict";
7
8
(function () {
9
// @ts-ignore
10
const vscode = acquireVsCodeApi();
11
12
function getSettings() {
13
const element = document.getElementById('settings');
14
if (element) {
15
const data = element.getAttribute('data-settings');
16
if (data) {
17
return JSON.parse(data);
18
}
19
}
20
21
throw new Error(`Could not load settings`);
22
}
23
24
const settings = getSettings();
25
26
// State
27
let hasLoadedMedia = false;
28
29
// Elements
30
const video = document.createElement('video');
31
if (settings.src !== null) {
32
video.src = settings.src;
33
}
34
video.playsInline = true;
35
video.controls = true;
36
video.autoplay = settings.autoplay;
37
video.muted = settings.autoplay;
38
video.loop = settings.loop;
39
40
function onLoaded() {
41
if (hasLoadedMedia) {
42
return;
43
}
44
hasLoadedMedia = true;
45
46
document.body.classList.remove('loading');
47
document.body.classList.add('ready');
48
document.body.append(video);
49
}
50
51
video.addEventListener('error', e => {
52
if (hasLoadedMedia) {
53
return;
54
}
55
56
hasLoadedMedia = true;
57
document.body.classList.add('error');
58
document.body.classList.remove('loading');
59
});
60
61
if (settings.src === null) {
62
onLoaded();
63
} else {
64
video.addEventListener('canplaythrough', () => {
65
onLoaded();
66
});
67
}
68
69
document.querySelector('.open-file-link')?.addEventListener('click', (e) => {
70
e.preventDefault();
71
vscode.postMessage({
72
type: 'reopen-as-text',
73
});
74
});
75
}());
76
77