video_player.php 22 KB

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