video_player.php 23 KB

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