| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117 |
- <!DOCTYPE html>
- <meta name="apple-mobile-web-app-capable" content="yes" />
- <meta name="viewport" content="user-scalable=no, width=device-width, initial-scale=1, maximum-scale=1"/>
- <html>
- <head>
- <meta charset="UTF-8">
- <meta name="theme-color" content="#000000">
- <script src="../script/jquery.min.js"></script>
- <script src="../script/ao_module.js"></script>
- <script src="backend/common.js"></script>
- <!-- ASS/SSA subtitle parser + renderer (see script/ass.js) -->
- <script src="script/ass.js"></script>
- <style>
- *, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
- :root {
- --accent: #0a84ff;
- --surface: #1c1c1e;
- --surface2: #2c2c2e;
- --text: #f5f5f7;
- --text-sub: #98989d;
- --transition: 0.2s ease;
- --radius: 0.4em;
- }
- html, body { width: 100%; height: 100%; background: #000; overflow: hidden; }
- #player-wrap {
- position: relative;
- width: 100%; height: 100%;
- display: flex; align-items: center; justify-content: center;
- background: #000;
- }
- #main-video {
- width: 100%; height: 100%;
- object-fit: contain; display: block; background: #000;
- }
- /* ── Controls overlay ──────────────────────────────────────────────── */
- #video-controls {
- position: absolute;
- bottom: 0; left: 0; right: 0;
- background: linear-gradient(transparent, rgba(0,0,0,0.85) 100%);
- padding: 40px 14px 12px;
- transition: opacity 0.3s;
- }
- #video-controls.hidden { opacity: 0; pointer-events: none; }
- #player-wrap:has(#video-controls.hidden) { cursor: none; }
- #progress-wrap {
- position: relative;
- height: 4px; background: rgba(255,255,255,0.25);
- border-radius: var(--radius); cursor: pointer; margin-bottom: 12px;
- }
- #progress-wrap:hover { height: 6px; }
- #progress-wrap::before {
- content: ''; position: absolute;
- top: -16px; left: 0; right: 0; height: 16px;
- }
- #progress-bar { height: 100%; border-radius: var(--radius); background: var(--accent); pointer-events: none; }
- #progress-thumb {
- position: absolute; top: 50%; transform: translateY(-50%);
- width: 14px; height: 14px;
- background: #fff; border-radius: 50%; pointer-events: none; display: none;
- }
- #progress-wrap:hover #progress-thumb { display: block; }
- #controls-row { display: flex; align-items: center; gap: 10px; }
- .ctrl-btn {
- background: none; border: none; cursor: pointer;
- color: #fff; padding: 4px; line-height: 1;
- transition: opacity var(--transition); outline: none;
- display: flex; align-items: center; justify-content: center;
- flex-shrink: 0;
- }
- .ctrl-btn:hover { opacity: 0.7; }
- .ctrl-btn img { width: 24px; height: 24px; display: block; }
- #volume-wrap { display: flex; align-items: center; gap: 8px; }
- #volume-slider {
- -webkit-appearance: none;
- width: 80px; height: 4px;
- background: rgba(255,255,255,0.3); border-radius: 4px; outline: none; cursor: pointer;
- }
- #volume-slider::-webkit-slider-thumb {
- -webkit-appearance: none;
- width: 12px; height: 12px; background: #fff; border-radius: 50%;
- }
- /* Portrait phones/tablets drive playback volume with the hardware keys,
- so the in-page slider only eats toolbar width. Users who want it back
- can force it on from the settings popup ("Volume bar → Always show"). */
- @media (max-width: 899px) and (orientation: portrait) {
- #volume-slider { display: none; }
- }
- body.always-show-volume #volume-slider { display: block; }
- #time-display {
- font-size: 13px; color: rgba(255,255,255,0.8);
- font-family: -apple-system, BlinkMacSystemFont, sans-serif;
- margin-left: 4px; white-space: nowrap;
- }
- #spacer { flex: 1; }
- /* ─── ASS subtitle overlay ───────────────────────────────────────────────────── */
- /* Sized in JS to the video's displayed rect so script coordinates land correctly
- regardless of letterboxing. Children are absolutely positioned by the renderer. */
- #ass-overlay {
- display: none;
- position: absolute;
- left: 0; top: 0; width: 0; height: 0;
- pointer-events: none;
- overflow: hidden;
- /* No z-index on purpose: subtitles sit directly after <video> in the DOM,
- so they paint above the (unpositioned) video but below every later
- positioned sibling — scrub preview, controls, menus and modals all stay
- on top of the text instead of being covered by it. */
- /* libass spaces lines by the font's own ascent+descent with no extra
- leading; 1.2 would push stacked dual-language lines apart and break
- the MarginV offsets releases use to sit them one above the other. */
- line-height: 1.05;
- }
- #ass-overlay.active { display: block; }
- /* ── Scrub-bar hover preview ───────────────────────────────────────── */
- #scrub-preview {
- display: none;
- position: absolute;
- bottom: 100%;
- margin-bottom: 12px;
- transform: translateX(-50%);
- pointer-events: none;
- z-index: 8;
- flex-direction: column;
- align-items: center;
- gap: 6px;
- }
- #scrub-preview.active { display: flex; }
- #scrub-preview-thumb {
- display: none;
- border-radius: 8px;
- background-color: #000;
- background-repeat: no-repeat;
- box-shadow: 0 4px 18px rgba(0,0,0,0.8), 0 0 0 2px rgba(255,255,255,0.14);
- }
- #scrub-preview-thumb.ready { display: block; }
- #scrub-preview-time {
- background: rgba(0,0,0,0.82);
- border-radius: 6px;
- padding: 3px 9px;
- font-size: 12px; font-weight: 600;
- color: #fff; white-space: nowrap;
- font-family: -apple-system, BlinkMacSystemFont, sans-serif;
- font-variant-numeric: tabular-nums;
- }
- /* ── Transcode-seek freeze frame ───────────────────────────────────── */
- /* Deliberately no z-index: both sit immediately after <video> in the DOM,
- so they paint above the (unpositioned) video but below every later
- positioned sibling — controls and menus stay on top and clickable. */
- #seek-freeze {
- display: none;
- position: absolute; inset: 0;
- width: 100%; height: 100%;
- object-fit: contain;
- background: #000;
- pointer-events: none;
- }
- #seek-spinner {
- display: none;
- position: absolute; inset: 0;
- align-items: center; justify-content: center;
- pointer-events: none;
- }
- #seek-spinner.active { display: flex; }
- .seek-spinner-box {
- display: flex; flex-direction: column;
- align-items: center; gap: 10px;
- background: rgba(0,0,0,0.55);
- backdrop-filter: blur(4px);
- -webkit-backdrop-filter: blur(4px);
- border-radius: 14px;
- padding: 18px 24px;
- font-size: 12px; color: var(--text);
- font-family: -apple-system, BlinkMacSystemFont, sans-serif;
- }
- .seek-spinner-box .spinner {
- width: 38px; height: 38px;
- border: 3px solid rgba(255,255,255,0.18);
- border-top-color: var(--accent);
- border-radius: 50%;
- animation: seekSpin 0.8s linear infinite;
- }
- @keyframes seekSpin { to { transform: rotate(360deg); } }
- /* ── Subtitle display ──────────────────────────────────────────────── */
- #subtitle-display {
- display: none;
- position: absolute;
- bottom: 72px; left: 50%; transform: translateX(-50%);
- width: 90%; text-align: center;
- pointer-events: none; /* z-index deliberately unset, see #ass-overlay */
- color: #fff; font-size: 22px; font-weight: 500; line-height: 1.45;
- text-shadow:
- -1px -1px 0 #000, 1px -1px 0 #000,
- -1px 1px 0 #000, 1px 1px 0 #000,
- 0 2px 6px rgba(0,0,0,0.85);
- }
- /* ── Centre play/pause flash indicator ─────────────────────────────── */
- #play-flash {
- position: absolute;
- top: 50%; left: 50%;
- width: 88px; height: 88px;
- margin: -44px 0 0 -44px;
- border-radius: 50%;
- background: rgba(0,0,0,0.55);
- backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
- display: flex; align-items: center; justify-content: center;
- pointer-events: none;
- opacity: 0; z-index: 18;
- }
- #play-flash img { width: 40px; height: 40px; display: block; }
- #play-flash.flash { animation: playFlash 0.62s ease-out; }
- @keyframes playFlash {
- 0% { opacity: 0; transform: scale(0.68); }
- 18% { opacity: 0.95; transform: scale(0.92); }
- 100% { opacity: 0; transform: scale(1.32); }
- }
- /* ── Resume popup ──────────────────────────────────────────────────── */
- #resume-popup {
- display: none;
- position: absolute; bottom: 90px; right: 20px; z-index: 25;
- background: rgba(22,22,24,0.97); backdrop-filter: blur(16px);
- border-radius: var(--radius); padding: 16px 18px; min-width: 240px;
- box-shadow: 0 4px 24px rgba(0,0,0,0.7), 0 0 0 1px rgba(255,255,255,0.1);
- animation: slideUpPopup 0.2s ease;
- color: var(--text);
- font-family: -apple-system, BlinkMacSystemFont, sans-serif;
- }
- #resume-popup.active { display: block; }
- @keyframes slideUpPopup {
- from { opacity: 0; transform: translateY(10px); }
- to { opacity: 1; transform: translateY(0); }
- }
- #resume-popup-title { font-size: 13px; font-weight: 600; margin-bottom: 4px; }
- #resume-popup-sub { font-size: 12px; color: var(--text-sub); margin-bottom: 12px; }
- #resume-popup-btns { display: flex; gap: 8px; }
- .resume-btn {
- flex: 1; padding: 8px; border: none; cursor: pointer;
- border-radius: calc(var(--radius) / 1.6); font-size: 12px; font-weight: 600;
- outline: none; transition: opacity var(--transition);
- }
- .resume-btn:hover { opacity: 0.8; }
- #resume-btn-continue { background: var(--accent); color: #fff; }
- #resume-btn-restart { background: var(--surface2); color: var(--text); }
- /* ── Context menu ──────────────────────────────────────────────────── */
- #player-ctx {
- display: none;
- position: absolute; z-index: 30;
- background: rgba(28,28,30,0.97);
- backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
- border-radius: var(--radius); padding: 4px 0; min-width: 192px;
- box-shadow: 0 4px 24px rgba(0,0,0,0.7), 0 0 0 1px rgba(255,255,255,0.08);
- user-select: none;
- font-family: -apple-system, BlinkMacSystemFont, sans-serif;
- }
- .ctx-item {
- padding: 9px 14px; font-size: 13px; cursor: pointer;
- display: flex; align-items: center; gap: 10px;
- color: var(--text); transition: background var(--transition);
- }
- .ctx-item:hover { background: rgba(255,255,255,0.08); }
- .ctx-item.ctx-active { color: var(--accent); }
- .ctx-item.ctx-disabled { opacity: 0.3; pointer-events: none; }
- .ctx-icon { width: 16px; text-align: center; flex-shrink: 0; font-style: normal; }
- img.ctx-icon { height: 16px; opacity: 0.85; display: block; }
- .ctx-divider { height: 1px; background: rgba(255,255,255,0.08); margin: 3px 0; }
- .ctx-has-sub { justify-content: space-between; position: relative; }
- .ctx-sub-arrow { font-style: normal; opacity: 0.55; font-size: 15px; }
- #ctx-subtitle-sub {
- display: none;
- position: absolute; top: 0; left: 100%;
- background: rgba(28,28,30,0.97);
- backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
- border-radius: calc(var(--radius) * 1.5); padding: 4px 0; min-width: 200px;
- box-shadow: 0 4px 24px rgba(0,0,0,0.7), 0 0 0 1px rgba(255,255,255,0.08);
- z-index: 32;
- }
- /* ── Subtitle settings modal ───────────────────────────────────────── */
- #subtitle-settings-modal {
- display: none;
- position: absolute; top: 50%; left: 50%;
- transform: translate(-50%, -50%);
- z-index: 40;
- background: rgba(18,18,20,0.97);
- backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
- border-radius: calc(var(--radius) / 1.5); padding: 20px 22px 18px; width: 340px;
- box-shadow: 0 8px 40px rgba(0,0,0,0.8), 0 0 0 1px rgba(255,255,255,0.1);
- color: var(--text);
- font-family: -apple-system, BlinkMacSystemFont, sans-serif;
- }
- #subtitle-settings-modal h3 {
- font-size: 14px; font-weight: 600; margin-bottom: 14px;
- display: flex; align-items: center; justify-content: space-between;
- }
- #sset-close {
- background: none; border: none; cursor: pointer;
- color: var(--text-sub); font-size: 17px; line-height: 1; padding: 0; outline: none;
- }
- #sset-close img { width: 14px; height: 14px; display: block; opacity: 0.55; transition: opacity var(--transition); }
- #sset-close:hover img { opacity: 1; }
- .sset-row {
- display: flex; align-items: center; gap: 10px;
- padding: 8px 0; border-bottom: 1px solid rgba(255,255,255,0.05);
- font-size: 12px;
- }
- .sset-row:last-child { border-bottom: none; }
- .sset-label { color: var(--text-sub); flex-shrink: 0; width: 56px; }
- .sset-seg {
- display: flex; background: var(--surface2);
- border-radius: calc(var(--radius) / 1.6); padding: 2px; gap: 2px; flex: 1;
- }
- .sset-seg-btn {
- flex: 1; padding: 4px 0; font-size: 12px; font-family: inherit;
- border: none; border-radius: calc(var(--radius) / 1.4); cursor: pointer;
- background: transparent; color: var(--text-sub);
- transition: background 0.15s, color 0.15s;
- }
- .sset-seg-btn.active { background: var(--surface); color: var(--text); }
- #sset-size { flex: 1; accent-color: var(--accent); cursor: pointer; }
- #sset-size-val { color: var(--text-sub); font-size: 11px; min-width: 32px; text-align: right; }
- #sset-font {
- flex: 1; background: var(--surface2); color: var(--text);
- border: 1px solid rgba(255,255,255,0.08); border-radius: calc(var(--radius) / 1.6);
- padding: 5px 8px; font-size: 12px; cursor: pointer; outline: none; appearance: auto;
- width: 100%;
- }
- .sset-colors { display: flex; align-items: center; gap: 7px; flex-wrap: wrap; flex: 1; }
- .sset-color {
- width: 22px; height: 22px; border-radius: 50%;
- border: 2px solid transparent; outline: 2px solid transparent;
- cursor: pointer; padding: 0; flex-shrink: 0;
- transition: outline-color 0.15s, transform 0.1s;
- }
- .sset-color:hover { transform: scale(1.12); }
- .sset-color.active { outline-color: var(--text); transform: scale(1.15); }
- #sset-color-custom {
- width: 22px; height: 22px; border-radius: 50%;
- border: 2px solid rgba(255,255,255,0.2); padding: 0;
- cursor: pointer; background: transparent; flex-shrink: 0;
- }
- #sset-color-custom.active { border-color: var(--text); transform: scale(1.15); }
- #sset-preview {
- margin-top: 14px; background: rgba(0,0,0,0.65);
- border-radius: calc(var(--radius) / 1.25); padding: 14px 12px; text-align: center; line-height: 1.4;
- }
- /* ── Video info modal ──────────────────────────────────────────────── */
- #video-info-modal {
- display: none;
- position: absolute; top: 50%; left: 50%;
- transform: translate(-50%, -50%);
- z-index: 40;
- background: rgba(18,18,20,0.97);
- backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
- border-radius: calc(var(--radius) / 1.5); padding: 20px 22px 16px; width: 340px;
- box-shadow: 0 8px 40px rgba(0,0,0,0.8), 0 0 0 1px rgba(255,255,255,0.1);
- color: var(--text);
- font-family: -apple-system, BlinkMacSystemFont, sans-serif;
- }
- #video-info-modal h3 {
- font-size: 14px; font-weight: 600; margin-bottom: 12px;
- display: flex; align-items: center; justify-content: space-between;
- }
- #video-info-close {
- background: none; border: none; cursor: pointer;
- color: var(--text-sub); font-size: 17px; line-height: 1; padding: 0; outline: none;
- }
- #video-info-close img { width: 14px; height: 14px; display: block; opacity: 0.55; transition: opacity var(--transition); }
- #video-info-close:hover img { opacity: 1; }
- #video-info-tabs {
- display: flex; gap: 3px;
- background: var(--surface2); border-radius: calc(var(--radius) / 1.25); padding: 3px; margin-bottom: 12px;
- }
- .info-tab {
- flex: 1; text-align: center; padding: 5px 0;
- font-size: 12px; font-weight: 500; border-radius: calc(var(--radius) / 1.6); cursor: pointer;
- color: var(--text-sub);
- transition: background var(--transition), color var(--transition);
- }
- .info-tab.active { background: var(--surface); color: var(--text); }
- .info-row {
- display: flex; gap: 8px;
- padding: 5px 0; border-bottom: 1px solid rgba(255,255,255,0.05);
- font-size: 12px; line-height: 1.4;
- }
- .info-row:last-child { border-bottom: none; }
- .info-label { color: var(--text-sub); flex-shrink: 0; width: 110px; }
- .info-value { color: var(--text); word-break: break-all; }
- /* ── Playback settings popup (gear button) ─────────────────────────── */
- #settings-popup {
- display: none;
- position: absolute;
- right: 14px; bottom: 62px;
- z-index: 35;
- background: rgba(28,28,30,0.97);
- backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
- border-radius: calc(var(--radius) * 1.5);
- padding: 6px 0; width: 236px;
- box-shadow: 0 4px 24px rgba(0,0,0,0.7), 0 0 0 1px rgba(255,255,255,0.08);
- color: var(--text);
- font-family: -apple-system, BlinkMacSystemFont, sans-serif;
- user-select: none;
- }
- #settings-popup.active { display: block; }
- .set-section { padding: 6px 14px 8px; }
- .set-section + .set-section { border-top: 1px solid rgba(255,255,255,0.08); }
- .set-head {
- display: flex; align-items: center; gap: 8px;
- font-size: 11px; font-weight: 600; letter-spacing: 0.3px;
- text-transform: uppercase; color: var(--text-sub);
- margin-bottom: 7px;
- }
- .set-head img { width: 14px; height: 14px; opacity: 0.7; display: block; }
- .set-seg {
- display: flex; background: var(--surface2);
- border-radius: calc(var(--radius) * 1.2); padding: 2px; gap: 2px;
- }
- .set-seg-btn {
- flex: 1; padding: 5px 0; font-size: 12px; font-family: inherit;
- border: none; border-radius: var(--radius); cursor: pointer;
- background: transparent; color: var(--text-sub);
- transition: background 0.15s, color 0.15s; outline: none;
- }
- .set-seg-btn:hover { color: var(--text); }
- .set-seg-btn.active { background: var(--surface); color: var(--text); }
- .speed-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 4px; }
- .speed-btn {
- padding: 5px 0; font-size: 12px; font-family: inherit;
- border: none; border-radius: var(--radius); cursor: pointer;
- background: var(--surface2); color: var(--text-sub);
- transition: background 0.15s, color 0.15s; outline: none;
- }
- .speed-btn:hover { color: var(--text); }
- .speed-btn.active { background: var(--accent); color: #fff; font-weight: 600; }
- .set-link {
- display: flex; align-items: center; gap: 9px;
- padding: 8px 14px; font-size: 13px; cursor: pointer;
- color: var(--text); transition: background var(--transition);
- }
- .set-link:hover { background: rgba(255,255,255,0.08); }
- .set-link img { width: 15px; height: 15px; opacity: 0.8; display: block; }
- /* ── Toast ─────────────────────────────────────────────────────────── */
- #toast {
- position: fixed; bottom: 30px; left: 50%;
- transform: translateX(-50%) translateY(20px);
- background: rgba(30,30,30,0.95); backdrop-filter: blur(8px);
- color: var(--text); padding: 10px 20px; border-radius: 20px;
- font-size: 13px; font-family: -apple-system, BlinkMacSystemFont, sans-serif;
- opacity: 0; transition: opacity 0.3s, transform 0.3s;
- pointer-events: none; z-index: 1000; max-width: min(90vw, 30em);
- text-align: center; line-height: 1.45;
- }
- #toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
- </style>
- </head>
- <body>
- <div id="player-wrap">
- <video id="main-video" preload="metadata"></video>
- <!-- Frozen last frame + spinner, shown while a transcode seek re-buffers.
- Must stay directly after <video> — stacking relies on DOM order. -->
- <canvas id="seek-freeze"></canvas>
- <div id="seek-spinner">
- <div class="seek-spinner-box">
- <div class="spinner"></div>
- <span>Buffering…</span>
- </div>
- </div>
- <!-- Styled ASS/SSA subtitles are drawn here, sized to the video's
- displayed rectangle. The plain #subtitle-display below is used
- for SubRip tracks. -->
- <div id="ass-overlay"></div>
- <!-- Subtitle overlay -->
- <div id="subtitle-display"></div>
- <!-- Centre play/pause flash indicator -->
- <div id="play-flash"><img id="play-flash-icon" src="img/icons/play_white.svg" alt=""></div>
- <!-- Resume popup -->
- <div id="resume-popup">
- <div id="resume-popup-title">Resume playback?</div>
- <div id="resume-popup-sub"></div>
- <div id="resume-popup-btns">
- <button class="resume-btn" id="resume-btn-continue">Resume</button>
- <button class="resume-btn" id="resume-btn-restart">Start over</button>
- </div>
- </div>
- <!-- Context menu -->
- <div id="player-ctx">
- <div class="ctx-item" id="ctx-play"><img class="ctx-icon" src="img/icons/play_white.svg" alt="">Play</div>
- <div class="ctx-item" id="ctx-pause"><img class="ctx-icon" src="img/icons/pause_white.svg" alt="">Pause</div>
- <div class="ctx-divider"></div>
- <div class="ctx-item" id="ctx-repeat"><img class="ctx-icon" src="img/icons/repeat_white.svg" alt="">Repeat: Off</div>
- <div class="ctx-divider"></div>
- <div class="ctx-item ctx-has-sub" id="ctx-subtitle-parent">
- <span>Subtitles</span>
- <i class="ctx-sub-arrow">›</i>
- <div id="ctx-subtitle-sub">
- <div class="ctx-item ctx-active" id="ctx-sub-disable"><i class="ctx-icon">✓</i>Disable</div>
- <div class="ctx-divider"></div>
- <div class="ctx-item" id="ctx-sub-load"><i class="ctx-icon">+</i>Load SRT file…</div>
- </div>
- </div>
- <div class="ctx-divider"></div>
- <div class="ctx-item" id="ctx-subtitle-settings"><img class="ctx-icon" src="img/icons/settings_white.svg" alt="">Subtitle Settings</div>
- <div class="ctx-item" id="ctx-props">Video Properties</div>
- </div>
- <!-- Subtitle settings modal -->
- <div id="subtitle-settings-modal">
- <h3>Subtitle Settings<button id="sset-close" title="Close"><img src="img/icons/close_white.svg" alt=""></button></h3>
- <div class="sset-row">
- <span class="sset-label">Position</span>
- <div class="sset-seg">
- <button class="sset-seg-btn active" data-val="bottom">Bottom</button>
- <button class="sset-seg-btn" data-val="top">Top</button>
- </div>
- </div>
- <div class="sset-row">
- <span class="sset-label">Size</span>
- <input type="range" id="sset-size" min="14" max="52" step="1" value="22">
- <span id="sset-size-val">22px</span>
- </div>
- <div class="sset-row">
- <span class="sset-label">Font</span>
- <select id="sset-font">
- <option value="system-ui, sans-serif">System Default</option>
- <option value="Arial, sans-serif">Arial</option>
- <option value="'Helvetica Neue', Helvetica, sans-serif">Helvetica</option>
- <option value="Georgia, serif">Georgia</option>
- <option value="'Times New Roman', Times, serif">Times New Roman</option>
- <option value="'Courier New', Courier, monospace">Courier New</option>
- <option value="Verdana, sans-serif">Verdana</option>
- <option value="'Trebuchet MS', sans-serif">Trebuchet MS</option>
- <option value="Impact, fantasy">Impact</option>
- </select>
- </div>
- <div class="sset-row">
- <span class="sset-label">Color</span>
- <div class="sset-colors">
- <button class="sset-color active" data-color="#ffffff" style="background:#ffffff" title="White"></button>
- <button class="sset-color" data-color="#ffff00" style="background:#ffff00" title="Yellow"></button>
- <button class="sset-color" data-color="#00ffff" style="background:#00ffff" title="Cyan"></button>
- <button class="sset-color" data-color="#00ff88" style="background:#00ff88" title="Green"></button>
- <button class="sset-color" data-color="#ff8800" style="background:#ff8800" title="Orange"></button>
- <input type="color" id="sset-color-custom" value="#ffffff" title="Custom color">
- </div>
- </div>
- <div id="sset-preview">Sample subtitle text</div>
- </div>
- <!-- Video info / stats modal -->
- <div id="video-info-modal">
- <h3><span id="video-info-title">Video Properties</span><button id="video-info-close" title="Close" onclick="closeVideoInfo()"><img src="img/icons/close_white.svg" alt=""></button></h3>
- <div id="video-info-tabs">
- <div class="info-tab active" onclick="showInfoTab('props')">Properties</div>
- <div class="info-tab" onclick="showInfoTab('stats')">Stats</div>
- </div>
- <div id="video-info-body"></div>
- </div>
- <!-- Playback settings popup -->
- <div id="settings-popup">
- <div class="set-section">
- <div class="set-head"><img src="img/icons/repeat_white.svg" alt="">Repeat</div>
- <div class="set-seg" id="set-repeat-seg">
- <button class="set-seg-btn active" data-repeat="off">Off</button>
- <button class="set-seg-btn" data-repeat="one">Repeat one</button>
- </div>
- </div>
- <div class="set-section">
- <div class="set-head"><img src="img/icons/play_white.svg" alt="">Playback speed</div>
- <div class="speed-grid" id="set-speed-grid">
- <button class="speed-btn" data-speed="0.5">0.5×</button>
- <button class="speed-btn active" data-speed="1">1×</button>
- <button class="speed-btn" data-speed="1.2">1.2×</button>
- <button class="speed-btn" data-speed="1.5">1.5×</button>
- <button class="speed-btn" data-speed="2">2×</button>
- </div>
- </div>
- <div class="set-section">
- <div class="set-head"><img src="img/icons/volume_white.svg" alt="">Volume bar</div>
- <div class="set-seg" id="set-volbar-seg">
- <button class="set-seg-btn active" data-volbar="auto">Auto</button>
- <button class="set-seg-btn" data-volbar="always">Always show</button>
- </div>
- </div>
- <div class="set-section">
- <div class="set-head"><img src="img/icons/movie_white.svg" alt="">Streaming mode</div>
- <div class="set-seg" id="set-stream-seg">
- <button class="set-seg-btn active" data-stream="auto">Auto</button>
- <button class="set-seg-btn" data-stream="mp4">MP4</button>
- <button class="set-seg-btn" data-stream="hls">HLS</button>
- </div>
- </div>
- <div class="set-section" style="padding-left:0;padding-right:0;padding-bottom:2px;">
- <div class="set-link" id="set-load-subtitle">
- <img src="img/icons/movie_white.svg" alt="">Load SRT subtitle…
- </div>
- <div class="set-link" id="set-subtitle-settings">
- <img src="img/icons/settings_white.svg" alt="">Subtitle settings
- </div>
- <div class="set-link" id="set-video-props">
- <img src="img/icons/menu_white.svg" alt="">Video properties
- </div>
- </div>
- </div>
- <!-- Player controls -->
- <div id="video-controls">
- <div id="progress-wrap">
- <div id="progress-bar" style="width:0%"></div>
- <div id="progress-thumb" style="left:0%"></div>
- <div id="scrub-preview">
- <div id="scrub-preview-thumb"></div>
- <div id="scrub-preview-time">0:00</div>
- </div>
- </div>
- <div id="controls-row">
- <button class="ctrl-btn" id="ctrl-play" title="Play / Pause (Space)">
- <img id="play-icon" src="img/icons/play_white.svg" alt="">
- </button>
- <div id="volume-wrap">
- <button class="ctrl-btn" id="ctrl-mute" title="Mute (M)">
- <img id="mute-icon" src="img/icons/volume_white.svg" alt="">
- </button>
- <input id="volume-slider" type="range" min="0" max="1" step="0.05" value="1">
- </div>
- <span id="time-display">0:00 / 0:00</span>
- <span id="spacer"></span>
- <button class="ctrl-btn" id="ctrl-settings" title="Playback settings">
- <img src="img/icons/settings_white.svg" alt="">
- </button>
- <button class="ctrl-btn" id="ctrl-fs" title="Fullscreen (F)">
- <img src="img/icons/fullscreen_white.svg" alt="">
- </button>
- </div>
- </div>
- </div><!-- #player-wrap -->
- <div id="toast"></div>
- <script>
- // ── State ─────────────────────────────────────────────────────────────────────
- var vid = document.getElementById('main-video');
- var currentFile = null; // {name, filepath, ext}
- var transcodeSeekOffset = 0; // seconds already streamed before current chunk
- var isTranscodedVideo = false;
- var transcodeDuration = 0; // total duration for transcoded video (from /media/duration/)
- var pendingResumePos = 0;
- var watchSaveInterval = null;
- var controlsTimer = null;
- var repeatSingle = (localStorage.getItem('movie_repeat_one') === '1');
- // Snapped to the nearest preset on load: an earlier build let this be dragged
- // to any value, and the popup highlights presets only.
- // The preset rates offered in the settings popup. Declared here rather than
- // beside setPlaybackSpeed because the initialiser below runs on load, and a
- // `var` further down the file would still be undefined at that point.
- var PLAYBACK_SPEEDS = [0.5, 1, 1.2, 1.5, 2];
- var playbackSpeed = nearestPlaybackSpeed(localStorage.getItem('movie_playback_speed') || '1');
- var alwaysShowVolumeBar = (localStorage.getItem('movie_always_volume_bar') === '1');
- var infoRefreshTimer = null;
- var currentInfoTab = 'props';
- // Subtitle state
- var loadedSubtitleFiles = []; // [{path, name, cues:[{start,end,text}]}]
- var activeSubtitleIndex = -1; // -1 = disabled
- // Subtitle settings (shared with main Movie window via localStorage)
- var subtitleSettings = { position: 'bottom', size: 22, font: 'system-ui, sans-serif', color: '#ffffff' };
- // ── Utilities ─────────────────────────────────────────────────────────────────
- function isWebPlayable(ext) {
- return ['mp4', 'webm', 'ogg'].indexOf(ext) !== -1;
- }
- function formatTime(s) {
- if (isNaN(s) || s < 0) { return '0:00'; }
- var h = Math.floor(s / 3600);
- var m = Math.floor((s % 3600) / 60);
- var sec = Math.floor(s % 60);
- var parts = [];
- if (h > 0) { parts.push(h); }
- parts.push(m);
- parts.push(sec < 10 ? '0' + sec : '' + sec);
- return parts.join(':');
- }
- function escapeHtml(str) {
- if (!str) { return ''; }
- return String(str)
- .replace(/&/g, '&').replace(/</g, '<')
- .replace(/>/g, '>').replace(/"/g, '"');
- }
- // Flash a large play/pause glyph in the centre of the video so the user gets
- // immediate feedback that their click / key press registered.
- function flashPlayState(isPlaying) {
- var $f = $('#play-flash');
- $('#play-flash-icon').attr('src',
- isPlaying ? 'img/icons/play_white.svg' : 'img/icons/pause_white.svg');
- $f.removeClass('flash');
- void $f[0].offsetWidth; // force reflow so the animation restarts
- $f.addClass('flash');
- }
- var toastTimer;
- function showToast(msg) {
- clearTimeout(toastTimer);
- $('#toast').text(msg).addClass('show');
- toastTimer = setTimeout(function () { $('#toast').removeClass('show'); }, 2800);
- }
- // play() returns a promise that rejects when the browser will not start the
- // media — most commonly NotSupportedError on Safari, which refuses a transcoded
- // stream because the endpoint cannot answer byte-range requests. Left
- // unhandled it only shows up as an unhandled rejection in the console, so the
- // player just sits there with no explanation. Surface it instead.
- function playVideo(v) {
- var p = v.play();
- if (p && typeof p.catch === 'function') {
- p.catch(function (err) {
- if (err && err.name === 'AbortError') {
- // Fired whenever a load or a new src interrupts a pending
- // play() — routine during seek-by-reload, not a failure.
- return;
- }
- if (err && err.name === 'NotSupportedError') {
- showToast('This browser cannot play this transcoded format. Try Chrome or Firefox.');
- } else {
- showToast('Playback failed: ' + ((err && err.message) || 'unknown error'));
- }
- });
- }
- return p;
- }
- // ── File loading ──────────────────────────────────────────────────────────────
- var files = ao_module_loadInputFiles();
- if (files && files.length > 0) {
- currentFile = {
- name: files[0].filename,
- filepath: files[0].filepath,
- ext: files[0].filename.split('.').pop().toLowerCase()
- };
- ao_module_setWindowTitle('Movie – ' + currentFile.name);
- isTranscodedVideo = !isWebPlayable(currentFile.ext);
- vid.autoplay = true;
- if (isTranscodedVideo) {
- if (!attachTranscodeStream(vid, transcodeStreamURL(currentFile.filepath, 0))) {
- showToast('HLS playback needs hls.js, which is not installed. Switch streaming mode to MP4 in settings.');
- }
- } else {
- vid.src = MEDIA_API + '?file=' + encodeURIComponent(currentFile.filepath);
- vid.load();
- }
- // Resume position check (only for videos longer than 1 hour)
- if (!isTranscodedVideo) {
- $(vid).one('loadedmetadata.resume', function () {
- if (vid.duration > 3600 && currentFile) {
- ao_module_agirun(SCRIPT_GET_WATCHTIME, { filepath: currentFile.filepath }, function (data) {
- if (data && !data.error && data.position > 30 && data.position < vid.duration * 0.95) {
- showResumePopup(data.position, vid.duration);
- }
- });
- }
- });
- } else {
- // Fetch total duration separately (transcode stream doesn't expose it)
- fetch(ao_root + 'media/duration/?file=' + encodeURIComponent(currentFile.filepath))
- .then(function (r) { return r.json(); })
- .then(function (data) {
- if (data.duration > 0) {
- transcodeDuration = data.duration;
- if (transcodeDuration > 3600 && currentFile) {
- ao_module_agirun(SCRIPT_GET_WATCHTIME, { filepath: currentFile.filepath }, function (wdata) {
- if (wdata && !wdata.error && wdata.position > 30 && wdata.position < transcodeDuration * 0.95) {
- showResumePopup(wdata.position, transcodeDuration);
- }
- });
- }
- }
- }).catch(function () {});
- }
- }
- // ── Scrub-bar hover preview (storyboard) ──────────────────────────────────────
- // The server renders one sprite sheet per file holding a downscaled frame every
- // few seconds; we fetch it once and keep it in memory, so hovering the timeline
- // costs nothing. Asking ffmpeg for a frame per hover would be hopeless on a
- // software-decoded H.265 source, which is exactly where previews matter most.
- var storyboard = null; // layout from the server + the loaded sheet URL
- var storyboardToken = 0; // invalidates in-flight loads when the file changes
- var storyboardTimer = null;
- function resetStoryboard() {
- storyboardToken++;
- storyboard = null;
- clearTimeout(storyboardTimer);
- storyboardTimer = null;
- $('#scrub-preview-thumb').removeClass('ready');
- hideScrubPreview();
- }
- // Building the sheet runs ffmpeg, so hold off briefly and let playback (and any
- // transcode) get established before adding more load.
- function scheduleStoryboardLoad(filepath) {
- resetStoryboard();
- if (!filepath) { return; }
- var token = storyboardToken;
- storyboardTimer = setTimeout(function () { loadStoryboard(filepath, token); }, 3000);
- }
- function loadStoryboard(filepath, token) {
- var base = STORYBOARD_API + '?file=' + encodeURIComponent(filepath);
- fetch(base)
- .then(function (r) { return r.json(); })
- .then(function (meta) {
- if (token !== storyboardToken) { return; } // switched file while loading
- if (!meta || meta.error || !meta.interval || !meta.tileWidth) { return; }
- var img = new Image();
- img.onload = function () {
- if (token !== storyboardToken) { return; }
- meta.url = img.src;
- storyboard = meta;
- };
- img.src = base + '&image=1';
- })
- .catch(function () {}); // previews are optional — stay silent on failure
- }
- // Whole-file duration, whichever playback mode is active
- function scrubTotalDuration() {
- if (isTranscodedVideo) { return transcodeDuration; }
- return vid.duration || 0;
- }
- function initScrubPreview() {
- var $wrap = $('#progress-wrap');
- $wrap.on('mousemove', function (e) {
- var total = scrubTotalDuration();
- var rect = this.getBoundingClientRect();
- if (!total || !isFinite(total) || rect.width <= 0) { hideScrubPreview(); return; }
- var ratio = Math.max(0, Math.min(1, (e.clientX - rect.left) / rect.width));
- showScrubPreview(ratio * total, ratio, rect.width);
- });
- $wrap.on('mouseleave', hideScrubPreview);
- }
- function showScrubPreview(time, ratio, barWidth) {
- $('#scrub-preview-time').text(formatTime(time));
- var $thumb = $('#scrub-preview-thumb');
- var halfWidth;
- if (storyboard && storyboard.url) {
- var idx = Math.max(0, Math.min(storyboard.count - 1,
- Math.floor(time / storyboard.interval)));
- var col = idx % storyboard.cols;
- var row = Math.floor(idx / storyboard.cols);
- $thumb.addClass('ready').css({
- 'width': storyboard.tileWidth + 'px',
- 'height': storyboard.tileHeight + 'px',
- 'background-image': 'url("' + storyboard.url + '")',
- 'background-position': (-col * storyboard.tileWidth) + 'px '
- + (-row * storyboard.tileHeight) + 'px'
- });
- halfWidth = storyboard.tileWidth / 2;
- } else {
- // Sheet not ready (or unavailable) — the timestamp alone is still useful
- $thumb.removeClass('ready');
- halfWidth = 28;
- }
- // Keep the popup within the bar rather than letting it hang off an edge
- var x = Math.max(halfWidth, Math.min(barWidth - halfWidth, ratio * barWidth));
- $('#scrub-preview').css('left', x + 'px').addClass('active');
- }
- function hideScrubPreview() { $('#scrub-preview').removeClass('active'); }
- // ── Transcode seek (seek-by-reload) ───────────────────────────────────────────
- // Formats the browser can't decode are streamed through ffmpeg, so "seeking"
- // means restarting the transcode at a new offset. Replacing .src blanks the
- // <video> to black until the first frame of the new segment arrives, which can
- // take seconds. Freeze the last painted frame under a spinner instead, and only
- // reveal the live element once it is genuinely playing again.
- var seekFreezeTimer = null;
- function showSeekFreeze() {
- var canvas = document.getElementById('seek-freeze');
- if (canvas && vid.videoWidth > 0 && vid.videoHeight > 0) {
- canvas.width = vid.videoWidth;
- canvas.height = vid.videoHeight;
- try {
- canvas.getContext('2d').drawImage(vid, 0, 0, canvas.width, canvas.height);
- $(canvas).show();
- } catch (e) {
- // No decodable frame right now (e.g. seeking again mid-buffer) —
- // leave whatever is already frozen on screen rather than flashing black.
- }
- }
- $('#seek-spinner').addClass('active');
- clearTimeout(seekFreezeTimer);
- // Safety net: a stalled transcode must never leave the overlay stuck on
- seekFreezeTimer = setTimeout(hideSeekFreeze, 30000);
- }
- function hideSeekFreeze() {
- clearTimeout(seekFreezeTimer);
- seekFreezeTimer = null;
- $('#seek-freeze').hide();
- $('#seek-spinner').removeClass('active');
- }
- // Seek to `seconds` (absolute, whole-file time), clamped to the known duration.
- //
- // An HLS stream keeps every segment produced so far in its playlist, so a seek
- // landing inside the transcoded window is an ordinary <video> seek — no reload,
- // no re-transcode, no black frame. Only a seek past that window (or an MP4
- // stream, which has no seekable history at all) has to restart the transcode at
- // the new offset.
- function transcodeSeekTo(seconds) {
- if (!currentFile) { return; }
- var pos = Math.max(0, seconds);
- if (transcodeDuration > 0) { pos = Math.min(transcodeDuration, pos); }
- if (usingHLS() && seekWithinTranscodedWindow(vid, pos)) {
- setSubtitleSeekFloor(pos);
- vid.currentTime = pos - transcodeSeekOffset;
- playVideo(vid);
- return;
- }
- showSeekFreeze();
- setSubtitleSeekFloor(pos);
- transcodeSeekOffset = pos;
- if (!attachTranscodeStream(vid, transcodeStreamURL(currentFile.filepath, pos))) {
- hideSeekFreeze();
- showToast('HLS playback needs hls.js, which is not installed. Switch streaming mode to MP4 in settings.');
- return;
- }
- playVideo(vid);
- }
- // Whether `pos` (absolute time) falls inside what the current stream has
- // already produced and can therefore be reached without reloading.
- function seekWithinTranscodedWindow(videoEl, pos) {
- var relative = pos - transcodeSeekOffset;
- if (relative < 0) { return false; }
- if (!videoEl.seekable || videoEl.seekable.length === 0) { return false; }
- var available = videoEl.seekable.end(videoEl.seekable.length - 1);
- // Stay a segment clear of the live edge; seeking right onto it stalls until
- // the next segment lands.
- return relative <= available - 4;
- }
- // Current playback position in whole-file terms (transcode streams restart at 0)
- function effectivePlaybackTime() {
- return isTranscodedVideo ? (vid.currentTime + transcodeSeekOffset) : vid.currentTime;
- }
- // ── Video controls ────────────────────────────────────────────────────────────
- function initVideoControls() {
- var $prog = $('#progress-bar');
- var $thumb = $('#progress-thumb');
- var $time = $('#time-display');
- // Restore saved volume
- var savedVol = parseFloat(localStorage.getItem('movie_volume'));
- if (!isNaN(savedVol) && savedVol >= 0 && savedVol <= 1) {
- vid.volume = savedVol;
- $('#volume-slider').val(savedVol);
- }
- if (localStorage.getItem('movie_muted') === '1') { vid.muted = true; }
- $('#ctrl-play').on('click', togglePlay);
- $(vid).on('click', togglePlay);
- $('#ctrl-mute').on('click', function () { vid.muted = !vid.muted; updateMuteIcon(); });
- $('#volume-slider').on('input', function () {
- vid.volume = parseFloat($(this).val());
- updateMuteIcon();
- });
- $('#ctrl-fs').on('click', toggleFullscreen);
- // Progress bar — seek-by-reload for transcoded streams
- $('#progress-wrap').on('click', function (e) {
- if (isTranscodedVideo && transcodeDuration > 0 && currentFile) {
- transcodeSeekTo((e.offsetX / $(this).width()) * transcodeDuration);
- return;
- }
- if (vid.duration) {
- vid.currentTime = (e.offsetX / $(this).width()) * vid.duration;
- }
- });
- // Progress + subtitle update on timeupdate
- $(vid).on('timeupdate', function () {
- updateSubtitleDisplay();
- if (isTranscodedVideo) {
- var displayTime = vid.currentTime + transcodeSeekOffset;
- if (transcodeDuration > 0) {
- var pct = (displayTime / transcodeDuration) * 100;
- $prog.css('width', pct + '%');
- $thumb.css('left', 'calc(' + pct + '% - 7px)');
- $time.text(formatTime(displayTime) + ' / ' + formatTime(transcodeDuration));
- } else {
- $time.text(formatTime(displayTime) + ' / --:--');
- }
- return;
- }
- if (!vid.duration) { return; }
- var pct = (vid.currentTime / vid.duration) * 100;
- $prog.css('width', pct + '%');
- $thumb.css('left', 'calc(' + pct + '% - 7px)');
- $time.text(formatTime(vid.currentTime) + ' / ' + formatTime(vid.duration));
- });
- $(vid).on('play', function () {
- $('#play-icon').attr('src', 'img/icons/pause_white.svg');
- if (watchSaveInterval) { clearInterval(watchSaveInterval); }
- watchSaveInterval = setInterval(function () {
- var effectiveDuration = isTranscodedVideo ? transcodeDuration : vid.duration;
- if (!vid.paused && effectiveDuration > 3600) { saveWatchPosition(); }
- }, 30000);
- });
- $(vid).on('pause', function () {
- $('#play-icon').attr('src', 'img/icons/play_white.svg');
- if (watchSaveInterval) { clearInterval(watchSaveInterval); watchSaveInterval = null; }
- var effectiveDuration = isTranscodedVideo ? transcodeDuration : vid.duration;
- var effectiveTime = isTranscodedVideo ? (vid.currentTime + transcodeSeekOffset) : vid.currentTime;
- if (effectiveDuration > 3600 && effectiveTime > 30) { saveWatchPosition(); }
- showControls();
- });
- $(vid).on('ended', function () {
- clearWatchPosition();
- if (watchSaveInterval) { clearInterval(watchSaveInterval); watchSaveInterval = null; }
- if (!repeatSingle) { return; }
- if (isTranscodedVideo && transcodeSeekOffset > 0 && currentFile) {
- // The stream started part-way in — restart it from the beginning
- transcodeSeekTo(0);
- } else {
- vid.currentTime = 0;
- playVideo(vid);
- }
- });
- $(vid).on('volumechange', function () {
- updateMuteIcon();
- localStorage.setItem('movie_volume', vid.volume);
- localStorage.setItem('movie_muted', vid.muted ? '1' : '0');
- });
- // Drop the transcode-seek freeze frame the moment the new segment is live.
- // 'playing' is the accurate signal; 'loadeddata' covers a seek made while
- // paused (where 'playing' never fires), and 'error' avoids a stuck overlay.
- // Any seek — native or transcode reload — re-bases the subtitle floor
- $(vid).on('seeking', function () { setSubtitleSeekFloor(effectivePlaybackTime()); });
- $(vid).on('playing', hideSeekFreeze);
- $(vid).on('loadeddata', function () { if (vid.paused) { hideSeekFreeze(); } });
- $(vid).on('error', hideSeekFreeze);
- // Auto-hide controls on mouse movement
- $('#player-wrap').on('mousemove touchstart', showControls);
- document.addEventListener('fullscreenchange', function () {
- if (!document.fullscreenElement) { showControls(); }
- });
- }
- function updateMuteIcon() {
- var isMuted = vid.muted || vid.volume === 0;
- $('#mute-icon').attr('src', isMuted ? 'img/icons/mute_white.svg' : 'img/icons/volume_white.svg');
- $('#volume-slider').val(vid.muted ? 0 : vid.volume);
- }
- function togglePlay() {
- $('#resume-popup').removeClass('active');
- var willPlay = vid.paused;
- if (willPlay) { playVideo(vid); } else { vid.pause(); }
- flashPlayState(willPlay);
- }
- function showControls() {
- $('#video-controls').removeClass('hidden');
- clearTimeout(controlsTimer);
- controlsTimer = setTimeout(function () {
- // Keep the bar up while the settings popup is open — it is anchored to it
- if (!vid.paused && !$('#settings-popup').hasClass('active')) {
- $('#video-controls').addClass('hidden');
- }
- }, 3000);
- }
- function toggleFullscreen() {
- var el = document.getElementById('player-wrap');
- if (!document.fullscreenElement) {
- (el.requestFullscreen || el.webkitRequestFullscreen || el.mozRequestFullScreen).call(el);
- } else {
- (document.exitFullscreen || document.webkitExitFullscreen || document.mozCancelFullScreen).call(document);
- }
- }
- // ── Watch position (resume) ───────────────────────────────────────────────────
- function saveWatchPosition() {
- if (!currentFile) { return; }
- var effectiveDuration = isTranscodedVideo ? transcodeDuration : vid.duration;
- var effectiveTime = isTranscodedVideo ? (vid.currentTime + transcodeSeekOffset) : vid.currentTime;
- if (!effectiveDuration || effectiveDuration < 3600 || effectiveTime < 10) { return; }
- ao_module_agirun(SCRIPT_SET_WATCHTIME, {
- filepath: currentFile.filepath,
- position: Math.floor(effectiveTime),
- duration: Math.floor(effectiveDuration)
- }, function () {}, function () {});
- }
- function clearWatchPosition() {
- if (!currentFile) { return; }
- ao_module_agirun(SCRIPT_SET_WATCHTIME,
- { filepath: currentFile.filepath, position: 0, duration: 0 },
- function () {}, function () {});
- }
- function showResumePopup(savedPos, duration) {
- vid.pause();
- pendingResumePos = savedPos;
- $('#resume-popup-sub').text(
- 'Last position: ' + formatTime(savedPos) + ' of ' + formatTime(duration)
- );
- $('#resume-popup').addClass('active');
- showControls();
- $('#resume-btn-continue').off('click').on('click', function () {
- if (isTranscodedVideo && currentFile) {
- transcodeSeekTo(pendingResumePos);
- } else {
- vid.currentTime = pendingResumePos;
- playVideo(vid);
- }
- $('#resume-popup').removeClass('active');
- });
- $('#resume-btn-restart').off('click').on('click', function () {
- playVideo(vid);
- $('#resume-popup').removeClass('active');
- });
- }
- // ── Context menu ──────────────────────────────────────────────────────────────
- function initContextMenu() {
- var $ctx = $('#player-ctx');
- $('#player-wrap').on('contextmenu', function (e) {
- e.preventDefault();
- if (!currentFile) { return; }
- $('#ctx-play').toggleClass('ctx-disabled', !vid.paused);
- $('#ctx-pause').toggleClass('ctx-disabled', vid.paused);
- $('#ctx-repeat')
- .toggleClass('ctx-active', repeatSingle)
- .html('<img class="ctx-icon" src="img/icons/'
- + (repeatSingle ? 'repeat_one_white.svg' : 'repeat_white.svg')
- + '" alt="">Repeat: ' + (repeatSingle ? 'On' : 'Off'));
- $('#ctx-subtitle-sub').hide();
- closeSettingsPopup();
- var rect = this.getBoundingClientRect();
- var x = e.clientX - rect.left;
- var y = e.clientY - rect.top;
- $ctx.css({ left: x, top: y, display: 'block' });
- var mw = $ctx.outerWidth(), mh = $ctx.outerHeight();
- if (x + mw > rect.width) { $ctx.css('left', Math.max(0, x - mw)); }
- if (y + mh > rect.height) { $ctx.css('top', Math.max(0, y - mh)); }
- showControls();
- });
- $(document).on('mousedown.ctx', function (e) {
- if (!$(e.target).closest('#player-ctx').length) { $ctx.hide(); }
- });
- $('#ctx-play').on('click', function () { playVideo(vid); flashPlayState(true); $ctx.hide(); });
- $('#ctx-pause').on('click', function () { vid.pause(); flashPlayState(false); $ctx.hide(); });
- $('#ctx-repeat').on('click', function () { setRepeatSingle(!repeatSingle); $ctx.hide(); });
- $('#ctx-subtitle-settings').on('click', function () { $ctx.hide(); openSubtitleSettings(); });
- $('#ctx-props').on('click', function () { $ctx.hide(); openVideoInfo('props'); });
- }
- // ── Playback settings popup (gear button) ─────────────────────────────────────
- function setAlwaysShowVolumeBar(on) {
- alwaysShowVolumeBar = !!on;
- localStorage.setItem('movie_always_volume_bar', alwaysShowVolumeBar ? '1' : '0');
- $('body').toggleClass('always-show-volume', alwaysShowVolumeBar);
- $('#set-volbar-seg .set-seg-btn').removeClass('active')
- .filter('[data-volbar="' + (alwaysShowVolumeBar ? 'always' : 'auto') + '"]').addClass('active');
- }
- function setRepeatSingle(on) {
- repeatSingle = !!on;
- vid.loop = false; // handled manually in the 'ended' handler
- localStorage.setItem('movie_repeat_one', repeatSingle ? '1' : '0');
- $('#set-repeat-seg .set-seg-btn').removeClass('active')
- .filter('[data-repeat="' + (repeatSingle ? 'one' : 'off') + '"]').addClass('active');
- }
- function setPlaybackSpeed(rate) {
- playbackSpeed = parseFloat(rate) || 1;
- vid.playbackRate = playbackSpeed;
- localStorage.setItem('movie_playback_speed', String(playbackSpeed));
- $('#set-speed-grid .speed-btn').removeClass('active')
- .filter('[data-speed="' + playbackSpeed + '"]').addClass('active');
- }
- // Snap an arbitrary stored rate onto the nearest preset, so the popup always
- // has exactly one button highlighted. Needed because an earlier build persisted
- // free-form rates from a drag slider.
- function nearestPlaybackSpeed(rate) {
- var value = parseFloat(rate);
- if (!value || value <= 0) { return 1; }
- return PLAYBACK_SPEEDS.reduce(function (best, preset) {
- return Math.abs(preset - value) < Math.abs(best - value) ? preset : best;
- }, PLAYBACK_SPEEDS[0]);
- }
- // Apply a streaming mode. Changing it mid-playback re-opens the current file on
- // the other transport, resuming where the viewer was.
- function applyStreamMode(mode, reloadCurrent) {
- var previous = getStreamMode();
- setStreamMode(mode);
- $('#set-stream-seg .set-seg-btn').removeClass('active')
- .filter('[data-stream="' + getStreamMode() + '"]').addClass('active');
- if (!reloadCurrent || previous === getStreamMode()) { return; }
- // Warn only when the viewer actively picks a mode this browser cannot play
- warnIfStreamModeUnplayable();
- if (!isTranscodedVideo || !currentFile) { return; }
- var resumeAt = effectivePlaybackTime();
- transcodeSeekOffset = 0;
- if (!attachTranscodeStream(vid, transcodeStreamURL(currentFile.filepath, 0))) {
- showToast('HLS playback needs hls.js, which is not installed.');
- return;
- }
- playVideo(vid);
- if (resumeAt > 1) { transcodeSeekTo(resumeAt); }
- }
- function playerVideoElement() { return vid; }
- // Surface the two streaming modes that cannot work on a given browser. Anything
- // that is simply working says nothing at all.
- function warnIfStreamModeUnplayable() {
- var mode = getStreamMode();
- if (mode === 'mp4' && isWebKitClient()) {
- showToast('This browser cannot play the MP4 stream. Use Auto or HLS.');
- } else if (mode === 'hls' && !hlsPlaybackSupported(playerVideoElement())) {
- showToast('HLS needs hls.js, which is not installed on this server.');
- }
- }
- function openSettingsPopup() {
- setRepeatSingle(repeatSingle);
- setPlaybackSpeed(playbackSpeed);
- setAlwaysShowVolumeBar(alwaysShowVolumeBar);
- applyStreamMode(getStreamMode(), false);
- $('#player-ctx').hide();
- $('#settings-popup').addClass('active');
- showControls();
- }
- function closeSettingsPopup() { $('#settings-popup').removeClass('active'); }
- function toggleSettingsPopup() {
- if ($('#settings-popup').hasClass('active')) { closeSettingsPopup(); }
- else { openSettingsPopup(); }
- }
- function initSettingsPopup() {
- $('#ctrl-settings').on('click', function (e) {
- e.stopPropagation();
- toggleSettingsPopup();
- });
- // Dismiss when clicking anywhere outside the popup or its button
- $(document).on('mousedown.setpop', function (e) {
- if (!$(e.target).closest('#settings-popup, #ctrl-settings').length) {
- closeSettingsPopup();
- }
- });
- $('#set-repeat-seg').on('click', '.set-seg-btn', function () {
- setRepeatSingle($(this).data('repeat') === 'one');
- });
- $('#set-speed-grid').on('click', '.speed-btn', function () {
- setPlaybackSpeed($(this).data('speed'));
- });
- $('#set-volbar-seg').on('click', '.set-seg-btn', function () {
- setAlwaysShowVolumeBar($(this).data('volbar') === 'always');
- });
- $('#set-stream-seg').on('click', '.set-seg-btn', function () {
- applyStreamMode(String($(this).data('stream')), true);
- });
- $('#set-load-subtitle').on('click', function () { closeSettingsPopup(); pickSubtitleFile(); });
- $('#set-subtitle-settings').on('click', function () { closeSettingsPopup(); openSubtitleSettings(); });
- $('#set-video-props').on('click', function () { closeSettingsPopup(); openVideoInfo('props'); });
- // Apply persisted values to the video element
- setRepeatSingle(repeatSingle);
- setPlaybackSpeed(playbackSpeed);
- setAlwaysShowVolumeBar(alwaysShowVolumeBar);
- applyStreamMode(getStreamMode(), false);
- // A transcode seek replaces the media source, which resets playbackRate —
- // reapply the chosen speed every time new media is loaded.
- $(vid).on('loadedmetadata', function () { vid.playbackRate = playbackSpeed; });
- }
- // ── Video info / stats modal ──────────────────────────────────────────────────
- function openVideoInfo(tab) {
- currentInfoTab = tab || 'props';
- $('#video-info-modal').show();
- $('.info-tab').removeClass('active').eq(currentInfoTab === 'props' ? 0 : 1).addClass('active');
- $('#video-info-title').text(currentInfoTab === 'props' ? 'Video Properties' : 'Streaming Stats');
- renderInfoContent();
- if (infoRefreshTimer) { clearInterval(infoRefreshTimer); infoRefreshTimer = null; }
- if (currentInfoTab === 'stats') {
- infoRefreshTimer = setInterval(renderInfoContent, 1000);
- }
- }
- function closeVideoInfo() {
- $('#video-info-modal').hide();
- if (infoRefreshTimer) { clearInterval(infoRefreshTimer); infoRefreshTimer = null; }
- }
- function showInfoTab(tab) {
- currentInfoTab = tab;
- $('.info-tab').removeClass('active').eq(tab === 'props' ? 0 : 1).addClass('active');
- $('#video-info-title').text(tab === 'props' ? 'Video Properties' : 'Streaming Stats');
- if (infoRefreshTimer) { clearInterval(infoRefreshTimer); infoRefreshTimer = null; }
- if (tab === 'stats') { infoRefreshTimer = setInterval(renderInfoContent, 1000); }
- renderInfoContent();
- }
- function infoRow(label, value) {
- return '<div class="info-row"><span class="info-label">' + escapeHtml(String(label)) + '</span>'
- + '<span class="info-value">' + escapeHtml(String(value)) + '</span></div>';
- }
- function renderInfoContent() {
- var html = '';
- if (currentInfoTab === 'props') {
- html += infoRow('Title', currentFile ? currentFile.name : '–');
- html += infoRow('Resolution', (vid.videoWidth && vid.videoHeight)
- ? vid.videoWidth + ' × ' + vid.videoHeight : '–');
- var infoDuration = isTranscodedVideo ? transcodeDuration : vid.duration;
- var infoPosition = isTranscodedVideo ? (vid.currentTime + transcodeSeekOffset) : vid.currentTime;
- html += infoRow('Duration', infoDuration ? formatTime(infoDuration) : '–');
- html += infoRow('Position', infoPosition ? formatTime(infoPosition) : '–');
- html += infoRow('Playback speed', vid.playbackRate + '×');
- html += infoRow('Volume', vid.muted ? 'Muted' : Math.round(vid.volume * 100) + '%');
- if (currentFile) { html += infoRow('File path', currentFile.filepath || '–'); }
- } else {
- var rsLabels = ['No info', 'Metadata only', 'Have current data', 'Have future data', 'Enough data'];
- var nsLabels = ['Empty', 'Idle', 'Loading', 'No source'];
- html += infoRow('Ready state', rsLabels[vid.readyState] || vid.readyState);
- html += infoRow('Network state', nsLabels[vid.networkState] || vid.networkState);
- var bufEnd = 0;
- if (vid.buffered && vid.buffered.length > 0) {
- for (var i = 0; i < vid.buffered.length; i++) {
- if (vid.buffered.start(i) <= vid.currentTime + 0.1) {
- bufEnd = Math.max(bufEnd, vid.buffered.end(i));
- }
- }
- }
- html += infoRow('Buffer ahead', Math.max(0, bufEnd - vid.currentTime).toFixed(1) + 's');
- html += infoRow('Total buffered', vid.buffered.length > 0
- ? formatTime(vid.buffered.end(vid.buffered.length - 1)) : '–');
- if (vid.getVideoPlaybackQuality) {
- var q = vid.getVideoPlaybackQuality();
- html += infoRow('Frames decoded', q.totalVideoFrames || 0);
- html += infoRow('Frames dropped', q.droppedVideoFrames || 0);
- }
- html += infoRow('Stalled / ended', vid.ended ? 'Ended' : (vid.readyState < 3 ? 'Yes' : 'No'));
- }
- $('#video-info-body').html(html);
- }
- // ── Subtitle settings ─────────────────────────────────────────────────────────
- function loadSubtitleSettings() {
- try {
- var s = JSON.parse(localStorage.getItem('movie_subtitle_settings') || 'null');
- if (s) { Object.assign(subtitleSettings, s); }
- } catch (e) {}
- }
- function saveSubtitleSettings() {
- localStorage.setItem('movie_subtitle_settings', JSON.stringify(subtitleSettings));
- }
- function applySubtitleSettings() {
- var s = subtitleSettings;
- $('#subtitle-display').css({
- 'font-size': s.size + 'px',
- 'font-family': s.font,
- 'color': s.color,
- 'bottom': s.position === 'bottom' ? '72px' : 'auto',
- 'top': s.position === 'top' ? '72px' : 'auto',
- 'transform': 'translateX(-50%)'
- });
- }
- function syncSettingsPreview() {
- var s = subtitleSettings;
- $('#sset-preview').css({
- 'font-size': s.size + 'px',
- 'font-family': s.font,
- 'color': s.color,
- 'text-shadow': '-1px -1px 0 #000, 1px -1px 0 #000, -1px 1px 0 #000, 1px 1px 0 #000, 0 2px 6px rgba(0,0,0,0.85)'
- });
- }
- function openSubtitleSettings() {
- var s = subtitleSettings;
- $('.sset-seg-btn').removeClass('active').filter('[data-val="' + s.position + '"]').addClass('active');
- $('#sset-size').val(s.size);
- $('#sset-size-val').text(s.size + 'px');
- $('#sset-font').val(s.font);
- var swatchMatch = $('.sset-color[data-color="' + s.color.toLowerCase() + '"]');
- $('.sset-color, #sset-color-custom').removeClass('active');
- if (swatchMatch.length) { swatchMatch.addClass('active'); }
- else { $('#sset-color-custom').addClass('active'); }
- $('#sset-color-custom').val(s.color);
- syncSettingsPreview();
- $('#subtitle-settings-modal').show();
- }
- function closeSubtitleSettings() { $('#subtitle-settings-modal').hide(); }
- function initSubtitleSettings() {
- loadSubtitleSettings();
- applySubtitleSettings();
- $('#sset-close').on('click', closeSubtitleSettings);
- $(document).on('click', '.sset-seg-btn', function () {
- subtitleSettings.position = $(this).data('val');
- $('.sset-seg-btn').removeClass('active');
- $(this).addClass('active');
- applySubtitleSettings();
- saveSubtitleSettings();
- });
- $('#sset-size').on('input', function () {
- subtitleSettings.size = parseInt($(this).val(), 10);
- $('#sset-size-val').text(subtitleSettings.size + 'px');
- applySubtitleSettings();
- syncSettingsPreview();
- saveSubtitleSettings();
- });
- $('#sset-font').on('change', function () {
- subtitleSettings.font = $(this).val();
- ensureEmbeddedFontLoaded(subtitleSettings.font); // no-op for built-in fonts
- applySubtitleSettings();
- syncSettingsPreview();
- saveSubtitleSettings();
- });
- $(document).on('click', '.sset-color', function () {
- subtitleSettings.color = $(this).data('color');
- $('.sset-color, #sset-color-custom').removeClass('active');
- $(this).addClass('active');
- $('#sset-color-custom').val(subtitleSettings.color);
- applySubtitleSettings();
- syncSettingsPreview();
- saveSubtitleSettings();
- });
- $('#sset-color-custom').on('input', function () {
- subtitleSettings.color = $(this).val();
- $('.sset-color').removeClass('active');
- $('#sset-color-custom').addClass('active');
- applySubtitleSettings();
- syncSettingsPreview();
- saveSubtitleSettings();
- });
- }
- // ── Subtitle loading / parsing / display ──────────────────────────────────────
- // Exposed on window so ao_module_openFileSelector can invoke it by name
- window.movieEmbOnSubtitleFile = function (raw) {
- var entry = Array.isArray(raw) ? raw[0] : raw;
- var filePath = (entry && typeof entry === 'object') ? entry.filepath : entry;
- if (!filePath || typeof filePath !== 'string') { return; }
- $.ajax({
- url: MEDIA_API + '?file=' + encodeURIComponent(filePath),
- dataType: 'text',
- success: function (content) {
- var name = filePath.replace(/\\/g, '/').split('/').pop();
- var cues = parseSrt(content);
- var existing = -1;
- loadedSubtitleFiles.forEach(function (sf, i) {
- if (sf.path === filePath) { existing = i; }
- });
- if (existing >= 0) {
- loadedSubtitleFiles[existing].cues = cues;
- activeSubtitleIndex = existing;
- } else {
- loadedSubtitleFiles.push({ path: filePath, name: name, cues: cues });
- activeSubtitleIndex = loadedSubtitleFiles.length - 1;
- }
- showToast('Subtitle loaded: ' + name);
- applyActiveSubtitle(); // a sidecar file replaces any styled track
- updateSubtitleSubmenu();
- },
- error: function () { showToast('Failed to load subtitle file'); }
- });
- };
- function parseSrtTime(t) {
- var m = t.match(/(\d+):(\d+):(\d+)[,.](\d+)/);
- if (!m) { return 0; }
- return parseInt(m[1]) * 3600 + parseInt(m[2]) * 60 + parseInt(m[3]) + parseInt(m[4]) / 1000;
- }
- function parseSrt(content) {
- var cues = [];
- var blocks = content.replace(/\r\n/g, '\n').replace(/\r/g, '\n').trim().split(/\n\n+/);
- blocks.forEach(function (block) {
- var lines = block.split('\n');
- var tcIdx = -1;
- for (var i = 0; i < lines.length; i++) {
- if (lines[i].indexOf('-->') !== -1) { tcIdx = i; break; }
- }
- if (tcIdx < 0) { return; }
- var parts = lines[tcIdx].split('-->');
- if (parts.length < 2) { return; }
- var start = parseSrtTime(parts[0].trim());
- var end = parseSrtTime(parts[1].trim().split(' ')[0]);
- // Strip inline SRT tags like <b>, <i>, <font>, plus any ASS override
- // blocks such as {\an8} or {\pos(x,y)}. ffmpeg's ASS-to-SubRip
- // conversion leaves positioning tags like those behind, so without this
- // they would be shown to the viewer as literal text.
- var text = lines.slice(tcIdx + 1).join('\n').trim()
- .replace(/<[^>]+>/g, '')
- .replace(/\{\\[^}]*\}/g, '')
- .trim();
- if (text) { cues.push({ start: start, end: end, text: text }); }
- });
- return cues;
- }
- function updateSubtitleDisplay() {
- // Styled tracks are drawn by the ASS renderer on its own frame loop
- if (assActive) { $('#subtitle-display').hide(); return; }
- if (activeSubtitleIndex < 0 || !loadedSubtitleFiles[activeSubtitleIndex]) {
- $('#subtitle-display').hide();
- return;
- }
- var currentTime = isTranscodedVideo
- ? (vid.currentTime + transcodeSeekOffset)
- : vid.currentTime;
- var cues = loadedSubtitleFiles[activeSubtitleIndex].cues;
- var found = null;
- for (var i = 0; i < cues.length; i++) {
- if (cues[i].start < subtitleSeekFloor) { continue; } // in flight when we landed
- if (currentTime >= cues[i].start && currentTime <= cues[i].end) { found = cues[i]; break; }
- }
- if (found) {
- $('#subtitle-display').html(escapeHtml(found.text).replace(/\n/g, '<br>')).show();
- } else {
- $('#subtitle-display').hide();
- }
- }
- // ── Embedded subtitle tracks and fonts ────────────────────────────────────────
- // MKV releases usually mux their subtitles (and the fonts they were typeset in)
- // into the container rather than shipping sidecar files. The server lists them
- // and extracts on demand; tracks are converted to SubRip, which keeps the text
- // and timing but drops ASS styling, positioning and karaoke.
- var embeddedSubtitles = []; // [{index, codec, language, title, forced, textual}]
- var embeddedFonts = []; // [{index, filename, mimetype}]
- var embeddedMediaPath = null; // file the two lists above describe
- var embeddedProbeToken = 0; // invalidates in-flight probes on file change
- var embeddedFontFaces = []; // FontFace objects registered for this video
- var embeddedFontsLoaded = {}; // family name -> already fetched
- function resetEmbeddedTracks() {
- embeddedProbeToken++;
- stopAssTrack();
- embeddedSubtitles = [];
- embeddedFonts = [];
- embeddedMediaPath = null;
- // Font families are keyed by attachment ordinal, which means the same name
- // refers to a different font in the next video — drop the old faces.
- embeddedFontFaces.forEach(function (face) {
- try { document.fonts.delete(face); } catch (e) {}
- });
- embeddedFontFaces = [];
- embeddedFontsLoaded = {};
- }
- function loadEmbeddedTrackList(filepath) {
- resetEmbeddedTracks();
- if (!filepath) { return; }
- embeddedMediaPath = filepath;
- var token = embeddedProbeToken;
- fetch(SUBTITLE_API + '?file=' + encodeURIComponent(filepath))
- .then(function (r) { return r.json(); })
- .then(function (info) {
- if (token !== embeddedProbeToken) { return; }
- if (!info || info.error) { return; }
- embeddedSubtitles = info.subtitles || [];
- embeddedFonts = info.fonts || [];
- updateSubtitleSubmenu();
- refreshEmbeddedFontOptions();
- })
- .catch(function () {}); // embedded tracks are a bonus — fail quietly
- }
- function embeddedTrackLabel(track, position) {
- var label = track.title || '';
- if (!label) { label = 'Track ' + (position + 1); }
- if (track.language) { label += ' [' + track.language + ']'; }
- if (track.forced) { label += ' (forced)'; }
- if (!track.textual) { label += ' — image based'; }
- return label;
- }
- // Extraction has to scan the whole container, so it takes a few seconds on a
- // large file. Results are kept in loadedSubtitleFiles, making reselection free.
- function selectEmbeddedSubtitle(track, position) {
- if (!track.textual) {
- showToast('That track is image based and cannot be displayed');
- return;
- }
- var cacheKey = 'embedded#' + track.index + '@' + embeddedMediaPath;
- for (var i = 0; i < loadedSubtitleFiles.length; i++) {
- if (loadedSubtitleFiles[i].path === cacheKey) {
- activeSubtitleIndex = i;
- applyActiveSubtitle();
- updateSubtitleSubmenu();
- return;
- }
- }
- // ASS/SSA is fetched in its native form so the styling survives; everything
- // else comes through as SubRip for the plain renderer.
- var styled = /^(ass|ssa)$/i.test(track.codec) && typeof ASS !== 'undefined';
- var mediaPath = embeddedMediaPath;
- var url = SUBTITLE_API + '?file=' + encodeURIComponent(mediaPath) + '&track=' + track.index
- + (styled ? '&format=ass' : '');
- showToast('Extracting subtitle track…');
- $.ajax({
- url: url,
- dataType: 'text',
- success: function (content) {
- if (mediaPath !== embeddedMediaPath) { return; } // episode changed
- if (styled) {
- var parsed = ASS.parse(content);
- if (!parsed.events.length) {
- showToast('That track contained no readable text');
- return;
- }
- loadedSubtitleFiles.push({
- path: cacheKey,
- name: embeddedTrackLabel(track, position),
- cues: [],
- assTrack: parsed
- });
- activeSubtitleIndex = loadedSubtitleFiles.length - 1;
- applyActiveSubtitle();
- updateSubtitleSubmenu();
- showToast('Subtitle loaded · ' + parsed.events.length + ' styled lines');
- return;
- }
- var cues = parseSrt(content);
- if (cues.length === 0) {
- showToast('That track contained no readable text');
- return;
- }
- loadedSubtitleFiles.push({
- path: cacheKey,
- name: embeddedTrackLabel(track, position),
- cues: cues
- });
- activeSubtitleIndex = loadedSubtitleFiles.length - 1;
- applyActiveSubtitle();
- updateSubtitleSubmenu();
- showToast('Subtitle loaded · ' + cues.length + ' lines');
- },
- error: function () { showToast('Could not extract that subtitle track'); }
- });
- }
- // Switch the display between the styled ASS renderer and the plain SubRip
- // overlay depending on what the newly selected track carries.
- function applyActiveSubtitle() {
- var entry = activeSubtitleIndex >= 0 ? loadedSubtitleFiles[activeSubtitleIndex] : null;
- if (entry && entry.assTrack) {
- startAssTrack(entry.assTrack);
- } else {
- stopAssTrack();
- updateSubtitleDisplay();
- }
- }
- // ── Subtitle seek floor ──────────────────────────────────────────────────────
- // After a seek, any line that had already begun before the landing point is
- // skipped entirely; only lines that start at or after it are shown. Seeking to
- // 1:02 with lines at 1:00-1:03 and 1:05-1:10 therefore shows nothing until 1:05.
- var subtitleSeekFloor = 0;
- function setSubtitleSeekFloor(time) {
- subtitleSeekFloor = Math.max(0, time || 0);
- if (assRenderer) { assRenderer.setSuppressBefore(subtitleSeekFloor); }
- updateSubtitleDisplay();
- }
- function resetSubtitleSeekFloor() { setSubtitleSeekFloor(0); }
- // ── Styled ASS rendering ─────────────────────────────────────────────────────
- // ASS tracks are fetched in their native form and drawn by script/ass.js, which
- // preserves per-line styling and position. That is what makes dual-language
- // releases work: the Japanese and Chinese lines are separate events shown at the
- // same time, and a single-cue renderer can only ever display one of them.
- var assRenderer = null;
- var assActive = false;
- var assFrameReq = null;
- function initAssRenderer() {
- var overlay = document.getElementById('ass-overlay');
- if (overlay && typeof ASS !== 'undefined') { assRenderer = new ASS.Renderer(overlay); }
- }
- // Match the overlay to the letterboxed picture inside the video element, so
- // script coordinates map onto what the viewer actually sees.
- function syncAssOverlayGeometry() {
- if (!assRenderer) { return; }
- var vid = document.getElementById('main-video');
- var overlay = document.getElementById('ass-overlay');
- var cw = vid.clientWidth, ch = vid.clientHeight;
- var vw = vid.videoWidth, vh = vid.videoHeight;
- // Until the decoder reports the picture size there is no way to know where
- // the letterbox bars are. Falling back to the raw element box would scale
- // the script against the black bars too and push bottom-anchored lines down
- // over the controls, so keep the last known good geometry instead.
- if (!(vw > 0 && vh > 0 && cw > 0 && ch > 0)) { return; }
- var scale = Math.min(cw / vw, ch / vh);
- var width = vw * scale;
- var height = vh * scale;
- var left = (cw - width) / 2;
- var top = (ch - height) / 2;
- if (overlay._w !== width || overlay._h !== height || overlay._l !== left || overlay._t !== top) {
- overlay._w = width; overlay._h = height; overlay._l = left; overlay._t = top;
- overlay.style.left = left + 'px';
- overlay.style.top = top + 'px';
- overlay.style.width = width + 'px';
- overlay.style.height = height + 'px';
- assRenderer.resize(width, height);
- }
- }
- function startAssTrack(track) {
- if (!assRenderer) { return; }
- stopAssTrack();
- assRenderer.setTrack(track);
- assActive = true;
- $('#ass-overlay').addClass('active');
- $('#subtitle-display').hide(); // the plain renderer must not double up
- loadAssFonts(track);
- var step = function () {
- if (!assActive) { return; }
- syncAssOverlayGeometry();
- assRenderer.setTime(effectivePlaybackTime());
- assFrameReq = requestAnimationFrame(step);
- };
- step();
- }
- function stopAssTrack() {
- assActive = false;
- if (assFrameReq) { cancelAnimationFrame(assFrameReq); assFrameReq = null; }
- if (assRenderer) { assRenderer.clear(); }
- $('#ass-overlay').removeClass('active');
- }
- // Only pull the fonts the track actually references — a release can attach a
- // dozen and use half of them.
- function loadAssFonts(track) {
- if (typeof ASS === 'undefined') { return; }
- ASS.referencedFonts(track).forEach(function (family) {
- ensureEmbeddedFontLoaded(family);
- });
- }
- // ── Embedded fonts ───────────────────────────────────────────────────────────
- // Registered under the font's own internal family name, which is what ASS styles
- // reference, and offered in Subtitle Settings for SubRip tracks. Fetched lazily:
- // a release can carry a dozen fonts and only a few are ever used.
- function embeddedFontFamily(font) {
- return font.family || ('aroz-embedded-' + font.index);
- }
- function findEmbeddedFontByFamily(family) {
- var wanted = String(family || '').replace(/^@/, '').toLowerCase();
- var found = null;
- embeddedFonts.forEach(function (f) {
- if (embeddedFontFamily(f).toLowerCase() === wanted) { found = f; }
- });
- return found;
- }
- function refreshEmbeddedFontOptions() {
- var $select = $('#sset-font');
- $select.find('optgroup.embedded-fonts').remove();
- if (embeddedFonts.length > 0) {
- var $group = $('<optgroup label="Embedded in this video" class="embedded-fonts"></optgroup>');
- embeddedFonts.forEach(function (font) {
- $group.append($('<option></option>')
- .attr('value', embeddedFontFamily(font))
- .text(font.filename || ('Font ' + (font.index + 1))));
- });
- $select.append($group);
- }
- // A font picked for a previous video may not exist in this one
- var stillOffered = $select.find('option').filter(function () {
- return this.value === subtitleSettings.font;
- }).length > 0;
- if (!stillOffered) {
- subtitleSettings.font = 'system-ui, sans-serif';
- applySubtitleSettings();
- saveSubtitleSettings();
- }
- $select.val(subtitleSettings.font);
- ensureEmbeddedFontLoaded(subtitleSettings.font);
- }
- function ensureEmbeddedFontLoaded(family) {
- if (!family || embeddedFontsLoaded[family] || !embeddedMediaPath) { return; }
- if (typeof FontFace === 'undefined' || !document.fonts) { return; }
- var meta = findEmbeddedFontByFamily(family);
- if (!meta) { return; } // a built-in font, or one this video does not carry
- embeddedFontsLoaded[family] = true; // claim it so we do not refetch in a loop
- var url = SUBTITLE_API + '?file=' + encodeURIComponent(embeddedMediaPath) + '&font=' + meta.index;
- var face = new FontFace(embeddedFontFamily(meta), 'url("' + url + '")');
- face.load().then(function (loaded) {
- document.fonts.add(loaded);
- embeddedFontFaces.push(loaded);
- applySubtitleSettings();
- syncSettingsPreview();
- if (assRenderer) { assRenderer.clear(); } // redraw with the real face
- }).catch(function () {
- embeddedFontsLoaded[family] = false;
- });
- }
- function updateSubtitleSubmenu() {
- $('#ctx-subtitle-sub .ctx-sub-dynamic').remove();
- var disabled = (activeSubtitleIndex < 0);
- $('#ctx-sub-disable')
- .toggleClass('ctx-active', disabled)
- .find('.ctx-icon').text(disabled ? '✓' : '');
- var $load = $('#ctx-sub-load');
- // Tracks muxed into the video, listed whether or not they are loaded yet
- if (embeddedSubtitles.length > 0) {
- $('<div class="ctx-divider ctx-sub-dynamic"></div>').insertBefore($load);
- embeddedSubtitles.forEach(function (track, position) {
- var cacheKey = 'embedded#' + track.index + '@' + embeddedMediaPath;
- var isActive = activeSubtitleIndex >= 0 &&
- loadedSubtitleFiles[activeSubtitleIndex] &&
- loadedSubtitleFiles[activeSubtitleIndex].path === cacheKey;
- $('<div class="ctx-item ctx-sub-dynamic'
- + (isActive ? ' ctx-active' : '')
- + (track.textual ? '' : ' ctx-disabled') + '">'
- + '<i class="ctx-icon">' + (isActive ? '✓' : '') + '</i>'
- + escapeHtml(embeddedTrackLabel(track, position))
- + '</div>')
- .on('click', function () {
- selectEmbeddedSubtitle(track, position);
- $('#player-ctx').hide();
- })
- .insertBefore($load);
- });
- }
- // Sidecar files the user loaded by hand
- var external = [];
- loadedSubtitleFiles.forEach(function (sf, idx) {
- if (String(sf.path).indexOf('embedded#') !== 0) { external.push({ sf: sf, idx: idx }); }
- });
- if (external.length > 0) {
- $('<div class="ctx-divider ctx-sub-dynamic"></div>').insertBefore($load);
- external.forEach(function (entry) {
- var isActive = (entry.idx === activeSubtitleIndex);
- $('<div class="ctx-item ctx-sub-dynamic' + (isActive ? ' ctx-active' : '') + '" data-sub-idx="' + entry.idx + '">'
- + '<i class="ctx-icon">' + (isActive ? '✓' : '') + '</i>'
- + escapeHtml(entry.sf.name)
- + '</div>')
- .on('click', function () {
- activeSubtitleIndex = parseInt($(this).data('sub-idx'), 10);
- applyActiveSubtitle();
- updateSubtitleSubmenu();
- $('#player-ctx').hide();
- })
- .insertBefore($load);
- });
- }
- }
- function initSubtitleMenu() {
- var $ctx = $('#player-ctx');
- var $parent = $('#ctx-subtitle-parent');
- var $sub = $('#ctx-subtitle-sub');
- var subHideTimer;
- function cancelSubHide() { clearTimeout(subHideTimer); }
- function scheduleSubHide() {
- subHideTimer = setTimeout(function () { $sub.hide(); }, 120);
- }
- $parent.on('mouseenter', function () {
- cancelSubHide();
- var ctxRight = $ctx.offset().left + $ctx.outerWidth();
- var containerRight = $('#player-wrap').offset().left + $('#player-wrap').outerWidth();
- if (ctxRight + 200 > containerRight) {
- $sub.css({ left: 'auto', right: '100%' });
- } else {
- $sub.css({ left: '100%', right: 'auto' });
- }
- $sub.show();
- });
- $parent.on('mouseleave', scheduleSubHide);
- $sub.on('mouseenter', cancelSubHide);
- $sub.on('mouseleave', scheduleSubHide);
- $('#ctx-sub-disable').on('click', function () {
- activeSubtitleIndex = -1;
- stopAssTrack();
- $('#subtitle-display').hide();
- updateSubtitleSubmenu();
- $ctx.hide();
- });
- $('#ctx-sub-load').on('click', function () {
- $ctx.hide();
- pickSubtitleFile();
- });
- }
- // Open the ArozOS file selector defaulted to the folder of the playing file
- function pickSubtitleFile() {
- var startDir = 'user:/';
- if (currentFile) {
- var fp = currentFile.filepath.replace(/\\/g, '/');
- var slash = fp.lastIndexOf('/');
- if (slash > 0) { startDir = fp.substring(0, slash); }
- }
- ao_module_openFileSelector(
- window.movieEmbOnSubtitleFile,
- startDir, 'file', false,
- { fnameOverride: 'movieEmbOnSubtitleFile', extAllowed: '.srt' }
- );
- }
- // ── Keyboard shortcuts ────────────────────────────────────────────────────────
- function initKeyboard() {
- $(document).on('keydown', function (e) {
- if ($(e.target).is('input, select, textarea')) { return; }
- switch (e.key) {
- case ' ':
- case 'k':
- e.preventDefault(); togglePlay(); showControls(); break;
- case 'ArrowRight':
- e.preventDefault();
- if (isTranscodedVideo && transcodeDuration > 0 && currentFile) {
- transcodeSeekTo(effectivePlaybackTime() + 10);
- } else {
- vid.currentTime = Math.min(vid.duration || 0, vid.currentTime + 10);
- }
- showControls(); break;
- case 'ArrowLeft':
- e.preventDefault();
- if (isTranscodedVideo && transcodeDuration > 0 && currentFile) {
- transcodeSeekTo(effectivePlaybackTime() - 10);
- } else {
- vid.currentTime = Math.max(0, vid.currentTime - 10);
- }
- showControls(); break;
- case 'ArrowUp':
- e.preventDefault();
- vid.volume = Math.min(1, Math.round((vid.volume + 0.1) * 10) / 10);
- showControls(); break;
- case 'ArrowDown':
- e.preventDefault();
- vid.volume = Math.max(0, Math.round((vid.volume - 0.1) * 10) / 10);
- showControls(); break;
- case 'f':
- case 'F':
- e.preventDefault(); toggleFullscreen(); break;
- case 'm':
- case 'M':
- e.preventDefault(); vid.muted = !vid.muted; break;
- case 'r':
- case 'R':
- e.preventDefault();
- setRepeatSingle(!repeatSingle);
- showToast('Repeat: ' + (repeatSingle ? 'On' : 'Off')); break;
- case 's':
- case 'S':
- e.preventDefault(); toggleSettingsPopup(); break;
- case 'Escape':
- e.preventDefault();
- $('#player-ctx').hide();
- closeSettingsPopup();
- closeVideoInfo();
- closeSubtitleSettings(); break;
- case 'MediaPlayPause':
- e.preventDefault(); togglePlay(); break;
- }
- });
- }
- // ── Init ──────────────────────────────────────────────────────────────────────
- function initMain(){
- initVideoControls();
- initContextMenu();
- initSettingsPopup();
- initScrubPreview();
- initAssRenderer();
- resetSubtitleSeekFloor(); // a freshly opened file starts unsuppressed
- if (currentFile) {
- scheduleStoryboardLoad(currentFile.filepath);
- loadEmbeddedTrackList(currentFile.filepath);
- }
- initSubtitleMenu();
- initSubtitleSettings();
- initKeyboard();
- }
- $(document).ready(function () {
- //Check if there are another instant running. If yes, replace that another instance URL
- if (ao_module_virtualDesktop){
- //If in ao_module mode, try to make this windows the only instance
- if (!ao_module_makeSingleInstance()){
- initMain();
- }
- }else{
- initMain();
- }
- });
- </script>
- </body>
- </html>
|