-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
121 lines (107 loc) · 2.58 KB
/
Copy pathindex.html
File metadata and controls
121 lines (107 loc) · 2.58 KB
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
<!DOCTYPE html>
<html>
<head>
<title>Keyboard Media</title>
<style>
* { margin: 0; padding: 0; box-sizing: border-box; }
body {
background: white;
overflow: hidden;
width: 100vw;
height: 100vh;
}
#bgImage {
position: fixed;
top: 0; left: 0;
width: 100%; height: 100%;
object-fit: cover;
display: none;
z-index: 1;
}
video {
position: fixed;
top: 0; left: 0;
width: 100%; height: 100%;
object-fit: cover;
display: none;
background: black;
z-index: 2;
}
</style>
</head>
<body>
<img id="bgImage" src="3.png" alt="">
<video id="videoPlayer" preload="auto" playsinline></video>
<audio id="audioPlayer" preload="auto"></audio>
<script>
const video = document.getElementById("videoPlayer");
const audio = document.getElementById("audioPlayer");
const bgImage = document.getElementById("bgImage");
const videoFiles = { "1": "1.mp4", "2": "2.mp4", "8": "8.mp4" };
const audioFiles = { "4": "4.mp3", "5": "5.mp3", "6": "6.mp3", "7": "7.mp3", "9": "9.mp3" };
function showBg() {
bgImage.style.display = "block";
}
function hideBg() {
bgImage.style.display = "none";
}
function stopVideo() {
video.pause();
video.removeAttribute("src");
video.load();
video.style.display = "none";
}
function stopAudio() {
audio.pause();
audio.removeAttribute("src");
audio.load();
}
async function playVideo(file) {
stopVideo();
stopAudio();
hideBg();
document.body.style.background = "black";
video.src = file;
video.load();
video.style.display = "block";
try {
await video.play();
} catch (err) {
console.log("Video error:", err);
}
video.onended = () => {
stopVideo();
document.body.style.background = "white";
};
}
async function playAudio(file) {
stopVideo();
stopAudio();
// Always show 3.png when audio plays
showBg();
audio.src = file;
audio.load();
try {
await audio.play();
} catch (err) {
console.log("Audio error:", err);
}
}
function showImage() {
stopVideo();
stopAudio();
showBg();
}
document.addEventListener("keydown", function(event) {
const key = event.key;
if (videoFiles[key]) {
playVideo(videoFiles[key]);
} else if (audioFiles[key]) {
playAudio(audioFiles[key]);
} else if (key === "3") {
showImage();
}
});
</script>
</body>
</html>