Skip to content

Commit 7193df0

Browse files
committed
q
1 parent ff91123 commit 7193df0

File tree

1 file changed

+101
-5
lines changed

1 file changed

+101
-5
lines changed

i.html

Lines changed: 101 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
font-family: Corbel, "Lucida Grande", "Lucida Sans Unicode", "Lucida Sans", "DejaVu Sans", "Bitstream Vera Sans",
1010
"Liberation Sans", Verdana, "Verdana Ref", sans-serif;
1111
}
12-
body.img {
12+
body.media {
1313
margin: 0;
1414
padding: 0;
1515
overflow: hidden;
@@ -21,13 +21,54 @@
2121
height: 100vh;
2222
}
2323

24-
body.img img {
24+
body.media img, body.media video {
2525
max-width: 100%;
2626
max-height: 100vh;
2727
width: auto;
2828
height: auto;
2929
display: block;
3030
}
31+
32+
video:focus {
33+
outline: none;
34+
}
35+
36+
.video-container {
37+
position: relative;
38+
display: none;
39+
}
40+
41+
.play-button {
42+
position: absolute;
43+
top: 50%;
44+
left: 50%;
45+
transform: translate(-50%, -50%);
46+
width: 80px;
47+
height: 80px;
48+
background-color: rgba(0, 0, 0, 0.6);
49+
border-radius: 50%;
50+
cursor: pointer;
51+
display: flex;
52+
justify-content: center;
53+
align-items: center;
54+
z-index: 10;
55+
}
56+
57+
.play-button:hover {
58+
background-color: rgba(0, 0, 0, 0.8);
59+
}
60+
61+
.play-button::after {
62+
content: '';
63+
display: block;
64+
width: 0;
65+
height: 0;
66+
border-top: 20px solid transparent;
67+
border-bottom: 20px solid transparent;
68+
border-left: 30px solid white;
69+
margin-left: 8px;
70+
}
71+
3172
#doc {
3273
display: none;
3374
}
@@ -39,7 +80,11 @@
3980
</style>
4081
</head>
4182
<body>
42-
<img />
83+
<img style="display: none;" />
84+
<div class="video-container">
85+
<video controls loop style="display: block;"></video>
86+
<div class="play-button"></div>
87+
</div>
4388
<div id="doc">
4489
<pre>
4590
Just put url to any image to use this document to present it.
@@ -103,14 +148,65 @@
103148
<div>
104149
<a href="?i=https://i.imgur.com/6N0MVlA.png">small image example</a>
105150
</div>
151+
152+
<br />
153+
154+
<div>
155+
<a href="?i=https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4">video example (mp4)</a>
156+
</div>
106157
</div>
107158
</body>
108159
<script>
109160
const i = new URLSearchParams(window.location.search).get("i");
110161

111162
if (i) {
112-
document.querySelector("img").src = i;
113-
document.body.classList.add("img");
163+
// Check if the URL is an MP4 file
164+
const isVideo = i.toLowerCase().endsWith('.mp4');
165+
166+
if (isVideo) {
167+
const videoContainer = document.querySelector(".video-container");
168+
const videoElement = document.querySelector("video");
169+
const playButton = document.querySelector(".play-button");
170+
171+
videoElement.src = i;
172+
videoContainer.style.display = "block";
173+
174+
// Add click event to the play button
175+
playButton.addEventListener("click", function() {
176+
videoElement.muted = false; // Ensure sound is on
177+
videoElement.play()
178+
.then(() => {
179+
// Hide play button when video plays successfully
180+
playButton.style.display = "none";
181+
})
182+
.catch(e => {
183+
console.log("Play failed:", e);
184+
});
185+
});
186+
187+
// Show play button again when video ends if not looping
188+
videoElement.addEventListener("ended", function() {
189+
if (!videoElement.loop) {
190+
playButton.style.display = "flex";
191+
}
192+
});
193+
194+
// Show play button if video is paused
195+
videoElement.addEventListener("pause", function() {
196+
playButton.style.display = "flex";
197+
});
198+
199+
// Hide play button if video is playing
200+
videoElement.addEventListener("playing", function() {
201+
playButton.style.display = "none";
202+
});
203+
} else {
204+
const imgElement = document.querySelector("img");
205+
imgElement.src = i;
206+
imgElement.style.display = "block";
207+
}
208+
209+
document.body.classList.add("media");
114210
} else {
115211
document.querySelector("#doc").removeAttribute("id");
116212

0 commit comments

Comments
 (0)