|
9 | 9 | font-family: Corbel, "Lucida Grande", "Lucida Sans Unicode", "Lucida Sans", "DejaVu Sans", "Bitstream Vera Sans",
|
10 | 10 | "Liberation Sans", Verdana, "Verdana Ref", sans-serif;
|
11 | 11 | }
|
12 |
| - body.img { |
| 12 | + body.media { |
13 | 13 | margin: 0;
|
14 | 14 | padding: 0;
|
15 | 15 | overflow: hidden;
|
|
21 | 21 | height: 100vh;
|
22 | 22 | }
|
23 | 23 |
|
24 |
| - body.img img { |
| 24 | + body.media img, body.media video { |
25 | 25 | max-width: 100%;
|
26 | 26 | max-height: 100vh;
|
27 | 27 | width: auto;
|
28 | 28 | height: auto;
|
29 | 29 | display: block;
|
30 | 30 | }
|
| 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 | + |
31 | 72 | #doc {
|
32 | 73 | display: none;
|
33 | 74 | }
|
|
39 | 80 | </style>
|
40 | 81 | </head>
|
41 | 82 | <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> |
43 | 88 | <div id="doc">
|
44 | 89 | <pre>
|
45 | 90 | Just put url to any image to use this document to present it.
|
|
103 | 148 | <div>
|
104 | 149 | <a href="?i=https://i.imgur.com/6N0MVlA.png">small image example</a>
|
105 | 150 | </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> |
106 | 157 | </div>
|
107 | 158 | </body>
|
108 | 159 | <script>
|
109 | 160 | const i = new URLSearchParams(window.location.search).get("i");
|
110 | 161 |
|
111 | 162 | 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"); |
114 | 210 | } else {
|
115 | 211 | document.querySelector("#doc").removeAttribute("id");
|
116 | 212 |
|
|
0 commit comments