video_player.php 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637
  1. <?php
  2. function ppvm_player($ppub, $path, $video) {
  3. $metadata = $ppub->metadata;
  4. $short_title = $metadata["title"];
  5. // if(strlen($short_title) > 30) {
  6. // $short_title = substr($short_title, 0, 30);
  7. // $short_title .= "…";
  8. // }
  9. ?>
  10. <!DOCTYPE html>
  11. <html lang="<?php echo($metadata["language"] ?? SITE_LANGUAGE);?>">
  12. <head>
  13. <meta charset="utf-8">
  14. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  15. <title><?php echo(htmlentities($metadata["title"]));?> - <?php echo(SITE_NAME);?></title>
  16. <meta name="description" content="<?php echo(htmlentities($metadata["description"]));?>">
  17. <meta name="author" content="<?php echo(htmlentities($metadata["author"]));?>">
  18. <link rel="alternate" type="application/x-ppub" title="<?php echo(htmlentities($metadata["title"]));?> (as PPUB)" href="?download=true" />
  19. <script type="text/javascript" src="<?php echo(SITE_URL);?>/ppvm_player.js"></script>
  20. <script type="text/javascript" src="<?php echo(SITE_URL);?>/custom-controls.js"></script>
  21. <style type="text/css">
  22. body {
  23. margin: 0px;
  24. background-color: #000;
  25. }
  26. video {
  27. display: block;
  28. width: 100%;
  29. height: 100%;
  30. object-fit: contain;
  31. }
  32. #video-container {
  33. position: relative;
  34. width: 100vw;
  35. height: 100vh;
  36. background-color: #000;
  37. }
  38. .additional-contols {
  39. background: rgba(45, 45, 45, 0.8);
  40. padding: 6px;
  41. color: #ffffff;
  42. position: absolute;
  43. top: -36px;
  44. left: 0;
  45. right: 0;
  46. opacity: 0;
  47. transition: 0.2s all;
  48. padding-top: 0px;
  49. padding-bottom: 0px;
  50. font-size: 14px;
  51. z-index: 2147483646; /* High z-index to stay visible in fullscreen */
  52. }
  53. /* Removed body:hover .additional-contols.javascript to let JavaScript handle visibility */
  54. .paused.javascript, .noscript {
  55. top: 0px;
  56. opacity: 1;
  57. }
  58. .additional-contols.show {
  59. top: 0px;
  60. opacity: 1;
  61. }
  62. /* Ensure top controls are visible in fullscreen mode */
  63. :fullscreen .additional-contols,
  64. :-webkit-full-screen .additional-contols,
  65. :-moz-full-screen .additional-contols,
  66. :-ms-fullscreen .additional-contols {
  67. opacity: 1 !important;
  68. top: 0 !important;
  69. z-index: 2147483646 !important;
  70. }
  71. /* Removed fullscreen hover rules to let JavaScript handle visibility */
  72. .noscript-text {
  73. white-space: nowrap;
  74. margin-right: 10px;
  75. margin-left: 30px;
  76. }
  77. body, input {
  78. font: 1rem -apple-system,BlinkMacSystemFont,"Segoe UI",Roboto, Helvetica,Arial,sans-serif,"Apple Color Emoji","Segoe UI Emoji", "Segoe UI Symbol";
  79. }
  80. dialog {
  81. background: rgba(45, 45, 45, 1);
  82. color: #ffffff;
  83. border: 1px solid aliceblue;
  84. max-width: 75%;
  85. }
  86. dialog p{
  87. margin-top: 2px;
  88. }
  89. dialog::backdrop {
  90. background: rgba(45, 45, 45, 0.8);
  91. }
  92. dialog .contents {
  93. margin: -15px;
  94. margin-bottom: 0px;
  95. padding: 15px;
  96. padding-bottom: 0px;
  97. max-height: calc(75vh - 55px);
  98. overflow-y: auto;
  99. }
  100. dialog .controls {
  101. border-top: 1px solid dimgrey;
  102. padding-top: 10px;
  103. }
  104. a {
  105. color: skyblue;
  106. }
  107. a:visited {
  108. color: aquamarine;
  109. }
  110. .additional-contols a {
  111. color: #ffffff;
  112. overflow: hidden;
  113. text-overflow: ellipsis;
  114. white-space: nowrap;
  115. flex-shrink: 2;
  116. }
  117. .additional-control {
  118. display: flex;
  119. flex-wrap: nowrap;
  120. align-items: baseline;
  121. justify-content: start;
  122. }
  123. .filler {
  124. flex: 1;
  125. }
  126. .site a {
  127. text-decoration: none;
  128. color: #ffffff;
  129. margin: 8px;
  130. }
  131. .site a:hover {
  132. color: skyblue;
  133. text-decoration: underline;
  134. }
  135. .additional-control button, .additional-control select {
  136. background: rgba(45, 45, 45, 0);
  137. border: 1px solid rgba(45, 45, 45, 0);
  138. color: #ffffff;
  139. cursor: pointer;
  140. text-decoration: underline;
  141. text-align: right;
  142. margin-top: 0px;
  143. margin-bottom: 2px;
  144. margin-left: 2px;
  145. margin-right: 2px;
  146. padding-left: 6px;
  147. padding-right: 6px;
  148. padding-bottom: 3px;
  149. padding-top: 1px;
  150. height: 23px;
  151. -webkit-appearance: none;
  152. }
  153. .additional-control select {
  154. margin-left: auto;
  155. }
  156. .additional-control button:hover, .additional-control select:hover {
  157. color: skyblue;
  158. }
  159. .additional-control button:focus, .additional-control select:focus {
  160. color: skyblue;
  161. }
  162. .additional-control select option {
  163. color: #000000;
  164. }
  165. summary {
  166. cursor: pointer;
  167. }
  168. #share-modal textarea, pre {
  169. width: 500px;
  170. background: rgb(30, 30, 30);
  171. color: #fff;
  172. border: none;
  173. padding: 8px;
  174. margin-top: 8px;
  175. margin-bottom: 18px;
  176. border-radius: 4px;
  177. overflow: scroll;
  178. white-space: pre;
  179. }
  180. #download-modal li {
  181. margin-bottom: 8px;
  182. }
  183. /* Custom Video Controls Styles */
  184. .video-controls {
  185. position: absolute;
  186. bottom: 0;
  187. left: 0;
  188. right: 0;
  189. background: rgba(45, 45, 45, 0.8);
  190. padding: 10px;
  191. color: #ffffff;
  192. opacity: 0;
  193. transition: opacity 0.3s ease;
  194. z-index: 10;
  195. }
  196. .video-controls.show {
  197. opacity: 1;
  198. }
  199. /* Removed body:hover .video-controls to let JavaScript handle visibility */
  200. .video-controls:hover,
  201. .video-controls:focus-within {
  202. opacity: 1;
  203. }
  204. /* Ensure controls are initially visible and properly positioned */
  205. #video-container .video-controls {
  206. position: absolute !important;
  207. bottom: 0 !important;
  208. left: 0 !important;
  209. right: 0 !important;
  210. }
  211. /* Ensure controls are properly positioned in fullscreen mode */
  212. :fullscreen #video-container .video-controls,
  213. :-webkit-full-screen #video-container .video-controls,
  214. :-moz-full-screen #video-container .video-controls,
  215. :-ms-fullscreen #video-container .video-controls {
  216. position: absolute;
  217. bottom: 0;
  218. left: 0;
  219. right: 0;
  220. z-index: 2147483647;
  221. }
  222. /* Ensure top controls are visible in fullscreen mode */
  223. :fullscreen .additional-contols,
  224. :-webkit-full-screen .additional-contols,
  225. :-moz-full-screen .additional-contols,
  226. :-ms-fullscreen .additional-contols {
  227. opacity: 1;
  228. top: 0;
  229. z-index: 2147483646;
  230. }
  231. .controls-row {
  232. display: flex;
  233. align-items: center;
  234. gap: 10px;
  235. }
  236. .control-btn {
  237. background: none;
  238. border: none;
  239. color: #ffffff;
  240. cursor: pointer;
  241. font-size: 18px;
  242. padding: 5px;
  243. border-radius: 3px;
  244. transition: background-color 0.2s;
  245. }
  246. .control-btn:hover {
  247. background-color: rgba(255, 255, 255, 0.2);
  248. }
  249. .control-btn:focus {
  250. outline: 2px solid skyblue;
  251. }
  252. .progress-container {
  253. flex: 1;
  254. position: relative;
  255. height: 5px;
  256. background-color: rgba(255, 255, 255, 0.3);
  257. border-radius: 2.5px;
  258. cursor: pointer;
  259. }
  260. .progress-bar {
  261. position: absolute;
  262. width: 100%;
  263. height: 100%;
  264. background-color: rgba(255, 255, 255, 0.3);
  265. border-radius: 2.5px;
  266. }
  267. .progress-filled {
  268. position: absolute;
  269. width: 0%;
  270. height: 100%;
  271. background-color: skyblue;
  272. border-radius: 2.5px;
  273. }
  274. .progress-buffered {
  275. position: absolute;
  276. width: 0%;
  277. height: 100%;
  278. background-color: rgba(135, 206, 250, 0.3);
  279. border-radius: 2.5px;
  280. }
  281. .seek-slider {
  282. position: absolute;
  283. width: 100%;
  284. height: 100%;
  285. opacity: 0;
  286. cursor: pointer;
  287. -webkit-appearance: none;
  288. appearance: none;
  289. background: transparent;
  290. }
  291. .seek-slider::-webkit-slider-thumb {
  292. -webkit-appearance: none;
  293. appearance: none;
  294. width: 15px;
  295. height: 15px;
  296. background: skyblue;
  297. border-radius: 50%;
  298. cursor: pointer;
  299. opacity: 0;
  300. transition: opacity 0.2s;
  301. }
  302. .seek-slider::-moz-range-thumb {
  303. width: 15px;
  304. height: 15px;
  305. background: skyblue;
  306. border-radius: 50%;
  307. cursor: pointer;
  308. opacity: 0;
  309. transition: opacity 0.2s;
  310. border: none;
  311. }
  312. .progress-container:hover .seek-slider::-webkit-slider-thumb,
  313. .progress-container:hover .seek-slider::-moz-range-thumb {
  314. opacity: 1;
  315. }
  316. .time-display {
  317. font-size: 14px;
  318. min-width: 100px;
  319. text-align: center;
  320. }
  321. .volume-container {
  322. display: flex;
  323. align-items: center;
  324. }
  325. .volume-slider {
  326. width: 80px;
  327. height: 5px;
  328. background: rgba(255, 255, 255, 0.3);
  329. border-radius: 2.5px;
  330. outline: none;
  331. -webkit-appearance: none;
  332. appearance: none;
  333. cursor: pointer;
  334. }
  335. .volume-slider::-webkit-slider-thumb {
  336. -webkit-appearance: none;
  337. appearance: none;
  338. width: 12px;
  339. height: 12px;
  340. background: skyblue;
  341. border-radius: 50%;
  342. cursor: pointer;
  343. }
  344. .volume-slider::-moz-range-thumb {
  345. width: 12px;
  346. height: 12px;
  347. background: skyblue;
  348. border-radius: 50%;
  349. cursor: pointer;
  350. border: none;
  351. }
  352. /* Responsive adjustments */
  353. @media (max-width: 768px) {
  354. .video-controls {
  355. padding: 8px;
  356. }
  357. .control-btn {
  358. font-size: 16px;
  359. padding: 3px;
  360. }
  361. .time-display {
  362. font-size: 12px;
  363. min-width: 80px;
  364. }
  365. .volume-slider {
  366. width: 60px;
  367. }
  368. }
  369. @media (max-width: 480px) {
  370. .controls-row {
  371. gap: 5px;
  372. }
  373. .time-display {
  374. display: none;
  375. }
  376. .volume-slider {
  377. width: 50px;
  378. }
  379. }
  380. </style>
  381. </head>
  382. <body>
  383. <div id="video-container">
  384. <video id="player" poster="<?php echo($video->metadata["poster"]);?>" preload="metadata" src="<?php echo($video->metadata["master"]);?>">
  385. </video>
  386. <!-- Top Controls (moved inside video container) -->
  387. <div id="controls" class="additional-contols paused">
  388. <div class="additional-control site">
  389. <a href="<?php echo(SITE_URL);?>/<?php echo($_GET["ppub"]);?>/<?php echo($_GET["asset"]);?>" target="_blank" title="<?php echo(htmlentities($metadata["title"]));?>"><strong><?php echo(htmlentities($short_title));?></strong></a>
  390. <button onclick="showInfo()">Info</button>
  391. <button onclick="shareVideo()">Share</button>
  392. <button onclick="downloadVideo()">Download</button>
  393. <select name="quality" id="quality-selector" onchange="qualitySelected()">
  394. </select>
  395. </div>
  396. </div>
  397. <!-- Custom Video Controls -->
  398. <div id="custom-controls" class="video-controls">
  399. <div class="controls-row">
  400. <button id="play-pause-btn" class="control-btn" aria-label="Play/Pause">▶</button>
  401. <div class="progress-container">
  402. <div id="progress-bar" class="progress-bar">
  403. <div id="progress-filled" class="progress-filled"></div>
  404. <div id="progress-buffered" class="progress-buffered"></div>
  405. </div>
  406. <input type="range" id="seek-slider" class="seek-slider" min="0" max="100" value="0" step="0.1">
  407. </div>
  408. <span id="time-display" class="time-display">0:00 / 0:00</span>
  409. <button id="mute-btn" class="control-btn" aria-label="Mute/Unmute">🔊</button>
  410. <div class="volume-container">
  411. <input type="range" id="volume-slider" class="volume-slider" min="0" max="1" value="1" step="0.1">
  412. </div>
  413. <button id="fullscreen-btn" class="control-btn" aria-label="Fullscreen">⛶</button>
  414. </div>
  415. </div>
  416. </div>
  417. <div id="no-script" class="additional-contols noscript">
  418. <div class="additional-control site">
  419. <a href="<?php echo(SITE_URL);?>/<?php echo($_GET["ppub"]);?>/<?php echo($_GET["asset"]);?>" target="_blank" title="<?php echo(htmlentities($metadata["title"]));?>"><strong><?php echo(htmlentities($short_title));?></strong></a>
  420. <span class="noscript-text">For the best experience, please enable JavaScript.</span>
  421. </div>
  422. </div>
  423. <dialog id="download-modal">
  424. <form method="dialog">
  425. <div class="contents">
  426. <p><strong>Download video</strong><br/>
  427. <a href="<?php echo($video->metadata["master"]); ?>" download>Download the full quality version of this video</a> or select a different version to suit your needs below.
  428. </p>
  429. <details>
  430. <summary>Other formats and versions</summary>
  431. <ul>
  432. <?php
  433. foreach ($video->entries as $entry) {
  434. $entry_asset = $ppub->asset_index[$entry->filename];
  435. echo(" <li><a href=\"" . $entry->filename . "\" download>" . htmlentities($entry->label) . "</a><br/>\n");
  436. echo(" <small>" . round(($entry_asset->end_location - $entry_asset->start_location) / 1000000, 2) . "MB, " . $entry_asset->mimetype . "</small></li>\n");
  437. }
  438. ?>
  439. </ul>
  440. </details>
  441. <p>
  442. <?php if ($ppub->metadata["copyright"] != null) { ?>
  443. <br/>
  444. <?php echo($ppub->metadata["copyright"]);?>
  445. <?php } if ($ppub->metadata["licence"] != null) { ?>
  446. <br/>
  447. <a href="<?php echo($ppub->metadata["licence"]);?>" target="_blank">See Licence</a>
  448. <?php } ?></p>
  449. </div>
  450. <div class="controls">
  451. <button value="cancel">Close</button>
  452. </div>
  453. </form>
  454. </dialog>
  455. <dialog id="info-modal">
  456. <form method="dialog">
  457. <div class="contents">
  458. <p><strong><?php echo(htmlentities($ppub->metadata["title"]));?></strong>
  459. <?php if($ppub->metadata["author"] != null) {
  460. preg_match("/^([^<]*(?= *<|$))<*([^>]*)>*/", $ppub->metadata["author"], $author);
  461. ?>
  462. <br/>By <?php
  463. if(isset($author[2]) && $author[2] != '') {
  464. echo("<a href=\"mailto:".$author[2]."\">");
  465. echo(htmlentities(trim($author[1])));
  466. echo("</a>");
  467. } else {
  468. echo(htmlentities($ppub->metadata["author"]));
  469. }
  470. ?>.
  471. <?php } if ($ppub->metadata["tags"] != null and USE_PPIX) { ?>
  472. <br/>Tagged with:
  473. <?php
  474. foreach(explode(" ", $ppub->metadata["tags"]) as $tag) {
  475. ?>
  476. <a href="<?php echo(SITE_URL);?>/?tag=<?php echo(urlencode($tag));?>" target="_blank"><?php echo(htmlentities($tag));?></a>
  477. <?php
  478. }
  479. ?>
  480. <?php } if ($ppub->metadata["date"] != null) { ?>
  481. <br/>Last updated on <?php echo(htmlentities((new DateTime($ppub->metadata["date"]))->format(DATE_FORMAT)));?>.
  482. <br/><?php } if ($ppub->metadata["copyright"] != null) { ?>
  483. <?php echo($ppub->metadata["copyright"]);?>
  484. <?php } if ($ppub->metadata["licence"] != null) { ?>
  485. <a href="<?php echo($ppub->metadata["licence"]);?>" target="_blank">See Licence</a>
  486. <?php } ?></p>
  487. <br/><small>Powered by <a href="https://github.com/Tilo15/php-ppub" target="_blank">php-ppub</a></small></p>
  488. </div>
  489. <div class="controls">
  490. <button value="cancel">Close</button>
  491. </div>
  492. </form>
  493. </dialog>
  494. <dialog id="share-modal">
  495. <form method="dialog">
  496. <div class="contents">
  497. <p><strong>Share this video</strong><br/>
  498. With your friends, colleagues, distant family, or strangers on the internet.
  499. </p>
  500. <div>
  501. <label>Link:</label>
  502. <pre><?php echo(SITE_URL);?>/<?php echo($_GET["ppub"]);?>/<?php echo($_GET["asset"]);?></pre>
  503. </div>
  504. <div>
  505. <label>Embed:</label><br/>
  506. <textarea readonly rows="3"><?php generate_embed($path, $video);?></textarea>
  507. </div>
  508. </div>
  509. <div class="controls">
  510. <button value="cancel" autofocus>Close</button>
  511. </div>
  512. </form>
  513. </dialog>
  514. <dialog id="unplayable-modal">
  515. <form method="dialog">
  516. <div class="contents">
  517. <p><strong>Unable to playback content</strong><br/>
  518. Your browser does not appear to support any of the available codecs.
  519. </p>
  520. </div>
  521. <div class="controls">
  522. <button value="cancel">Close</button>
  523. </div>
  524. </form>
  525. </dialog>
  526. <script type="text/javascript">
  527. setup_playback({
  528. entries: [
  529. <?php
  530. foreach ($video->entries as $entry) {
  531. $entry_asset = $ppub->asset_index[$entry->filename];
  532. $size = ($entry_asset->end_location - $entry_asset->start_location);
  533. echo(" { type: \"" . $entry->type . "\", mimetype: \"" . $entry_asset->mimetype . "\", path: \"" . $entry->filename . "\", label: \"" . $entry->label . "\", byterate: " . $size / (float)$video->metadata["duration"] . ", filesize: " . $size . ", metadata: { ");
  534. foreach ($entry->metadata as $key => $val) {
  535. echo(str_replace("-", "_", $key) . ": \"" . $val . "\", ");
  536. }
  537. echo("}},\n");
  538. }
  539. ?>
  540. ]
  541. });
  542. </script>
  543. </body>
  544. </html>
  545. <?php
  546. }
  547. function generate_embed($path, $video) {
  548. $percent = 56.25;
  549. if(isset($video->metadata["ratio"])) {
  550. $ratio = explode(":", $video->metadata["ratio"]);
  551. $percent = (min($ratio[0], $ratio[1]) / max($ratio[0], $ratio[1])) * 100;
  552. }
  553. ?>
  554. <div class="ppvm-player" style="position: relative; height:0; background: #2d2d2d; padding-bottom: <?php echo($percent);?>%">
  555. <iframe src="<?php echo(SITE_URL);?>/<?php echo($_GET["ppub"]);?>/<?php echo($_GET["asset"]);?>?embed=true/" style="position: absolute; top: 0; left: 0; width: 100%; height: 100%;" allowfullscreen></iframe>
  556. </div><?php
  557. }
  558. ?>