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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!doctype html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="utf-8" />
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
| 6 |
+
<title>hf-dash-cors-test</title>
|
| 7 |
+
<style>
|
| 8 |
+
:root{
|
| 9 |
+
--bg:#0b1020;--panel:#121a31;--panel2:#18223f;--text:#e8ecf8;--muted:#a8b4d4;--ok:#38d39f;--warn:#ffcc66;--bad:#ff7676;--line:#2a355b;--accent:#78a7ff;
|
| 10 |
+
}
|
| 11 |
+
*{box-sizing:border-box} html,body{margin:0;padding:0;background:var(--bg);color:var(--text);font:16px/1.5 system-ui,-apple-system,Segoe UI,Roboto,sans-serif}
|
| 12 |
+
.wrap{max-width:1220px;margin:0 auto;padding:24px}
|
| 13 |
+
h1{font-size:clamp(1.8rem,3vw,2.5rem);margin:0 0 8px}
|
| 14 |
+
h2{font-size:1.1rem;margin:0 0 10px}
|
| 15 |
+
p{color:var(--muted);margin:8px 0}
|
| 16 |
+
.grid{display:grid;grid-template-columns:1.15fr .85fr;gap:18px}
|
| 17 |
+
@media (max-width:960px){.grid{grid-template-columns:1fr}}
|
| 18 |
+
.card{background:linear-gradient(180deg,var(--panel),var(--panel2));border:1px solid var(--line);border-radius:16px;padding:18px;box-shadow:0 10px 30px rgba(0,0,0,.24)}
|
| 19 |
+
label{display:block;font-weight:700;margin:14px 0 6px}
|
| 20 |
+
input,textarea{width:100%;background:#0d1430;color:var(--text);border:1px solid var(--line);border-radius:12px;padding:12px}
|
| 21 |
+
textarea{min-height:110px;resize:vertical}
|
| 22 |
+
.row{display:flex;gap:10px;flex-wrap:wrap;margin-top:14px}
|
| 23 |
+
button{background:var(--accent);color:#08101f;border:0;border-radius:12px;padding:11px 14px;font-weight:700;cursor:pointer}
|
| 24 |
+
button.secondary{background:#223158;color:var(--text)}
|
| 25 |
+
pre{background:#08101f;border:1px solid var(--line);border-radius:12px;padding:14px;white-space:pre-wrap;word-break:break-word;min-height:360px;max-height:680px;overflow:auto}
|
| 26 |
+
.kpis{display:grid;grid-template-columns:repeat(4,1fr);gap:10px;margin-top:12px}
|
| 27 |
+
@media (max-width:760px){.kpis{grid-template-columns:repeat(2,1fr)}}
|
| 28 |
+
.kpi{background:#0d1430;border:1px solid var(--line);border-radius:12px;padding:12px}
|
| 29 |
+
.v{font-size:1.1rem;font-weight:800}
|
| 30 |
+
.ok{color:var(--ok)} .warn{color:var(--warn)} .bad{color:var(--bad)}
|
| 31 |
+
code{background:#0d1430;padding:2px 6px;border-radius:6px}
|
| 32 |
+
video{width:100%;aspect-ratio:16/9;background:black;border-radius:12px;border:1px solid var(--line)}
|
| 33 |
+
.small{font-size:.92rem;color:var(--muted)}
|
| 34 |
+
ul{padding-left:18px}
|
| 35 |
+
.mono{font-family:ui-monospace,SFMono-Regular,Menlo,Consolas,monospace}
|
| 36 |
+
</style>
|
| 37 |
+
</head>
|
| 38 |
+
<body>
|
| 39 |
+
<div class="wrap">
|
| 40 |
+
<h1>Hugging Face DASH/CORS test page</h1>
|
| 41 |
+
<p>Host this on a different origin than <code>huggingface.co</code>. It tests whether JavaScript can fetch a DASH manifest, whether sample segments are readable cross-origin, and whether a real dash.js player can start playback from your Hugging Face-hosted assets.</p>
|
| 42 |
+
<div class="grid">
|
| 43 |
+
<section class="card">
|
| 44 |
+
<h2>Inputs</h2>
|
| 45 |
+
<label for="manifestUrl">DASH manifest URL (.mpd)</label>
|
| 46 |
+
<input id="manifestUrl" type="url" spellcheck="false" value="https://huggingface.co/datasets/USERNAME/REPO/resolve/main/dash/manifest.mpd" />
|
| 47 |
+
|
| 48 |
+
<label for="sampleSegments">Sample segment URLs to test directly (one per line)</label>
|
| 49 |
+
<textarea id="sampleSegments" spellcheck="false">https://huggingface.co/datasets/USERNAME/REPO/resolve/main/dash/init.mp4
|
| 50 |
+
https://huggingface.co/datasets/USERNAME/REPO/resolve/main/dash/chunk-00001.m4s</textarea>
|
| 51 |
+
|
| 52 |
+
<label for="customHeaders">Optional extra headers for preflight testing (JSON)</label>
|
| 53 |
+
<textarea id="customHeaders" spellcheck="false">{}</textarea>
|
| 54 |
+
|
| 55 |
+
<div class="row">
|
| 56 |
+
<button id="testManifest">Test manifest fetch()</button>
|
| 57 |
+
<button id="testSegments" class="secondary">Test sample segments</button>
|
| 58 |
+
<button id="startDash" class="secondary">Start dash.js player</button>
|
| 59 |
+
<button id="clearLog" class="secondary">Clear log</button>
|
| 60 |
+
</div>
|
| 61 |
+
|
| 62 |
+
<div class="kpis">
|
| 63 |
+
<div class="kpi"><div class="small">Manifest fetch</div><div id="manifestStatus" class="v">β</div></div>
|
| 64 |
+
<div class="kpi"><div class="small">Segments</div><div id="segmentStatus" class="v">β</div></div>
|
| 65 |
+
<div class="kpi"><div class="small">dash.js</div><div id="dashStatus" class="v">β</div></div>
|
| 66 |
+
<div class="kpi"><div class="small">Video element</div><div id="videoStatus" class="v">β</div></div>
|
| 67 |
+
</div>
|
| 68 |
+
|
| 69 |
+
<label for="log">Log</label>
|
| 70 |
+
<pre id="log"></pre>
|
| 71 |
+
</section>
|
| 72 |
+
|
| 73 |
+
<aside class="card">
|
| 74 |
+
<h2>Player and guidance</h2>
|
| 75 |
+
<video id="player" controls preload="metadata"></video>
|
| 76 |
+
<p class="small">Open DevTools Network and Console while testing. Browser CORS failures are often clearer there than in JavaScript errors.</p>
|
| 77 |
+
<ul>
|
| 78 |
+
<li>If <code>manifest fetch()</code> fails, your JS player cannot even read the MPD.</li>
|
| 79 |
+
<li>If the MPD fetch works but sample segment fetches fail, the manifest may be readable while the actual media chunks are blocked.</li>
|
| 80 |
+
<li>If dash.js throws errors even though direct fetches look okay, the problem may be codec/container compatibility rather than CORS.</li>
|
| 81 |
+
<li>Use stable Hugging Face <code>/resolve/main/...</code> URLs here, not the temporary signed <code>cas-bridge...</code> URL.</li>
|
| 82 |
+
</ul>
|
| 83 |
+
<p class="small mono">Suggested repo layout:<br>dash/manifest.mpd<br>dash/video/init.mp4<br>dash/video/chunk-00001.m4s<br>dash/audio/init.mp4<br>dash/audio/chunk-00001.m4s</p>
|
| 84 |
+
</aside>
|
| 85 |
+
</div>
|
| 86 |
+
</div>
|
| 87 |
+
|
| 88 |
+
<script src="https://cdn.dashjs.org/v5.0.3/modern/umd/dash.all.min.js"></script>
|
| 89 |
+
<script>
|
| 90 |
+
const $ = (id) => document.getElementById(id);
|
| 91 |
+
const logEl = $('log');
|
| 92 |
+
const playerEl = $('player');
|
| 93 |
+
const manifestStatus = $('manifestStatus');
|
| 94 |
+
const segmentStatus = $('segmentStatus');
|
| 95 |
+
const dashStatus = $('dashStatus');
|
| 96 |
+
const videoStatus = $('videoStatus');
|
| 97 |
+
let player;
|
| 98 |
+
|
| 99 |
+
function log(msg, cls=''){
|
| 100 |
+
const line = `[${new Date().toLocaleTimeString()}] ${msg}`;
|
| 101 |
+
const div = document.createElement('div');
|
| 102 |
+
div.textContent = line;
|
| 103 |
+
if (cls) div.className = cls;
|
| 104 |
+
logEl.appendChild(div);
|
| 105 |
+
logEl.scrollTop = logEl.scrollHeight;
|
| 106 |
+
console.log(line);
|
| 107 |
+
}
|
| 108 |
+
function setStatus(el, text, cls=''){ el.textContent = text; el.className = `v ${cls}`; }
|
| 109 |
+
function getManifest(){ return $('manifestUrl').value.trim(); }
|
| 110 |
+
function getHeaders(){
|
| 111 |
+
const raw = $('customHeaders').value.trim() || '{}';
|
| 112 |
+
try { return JSON.parse(raw); }
|
| 113 |
+
catch (e) { throw new Error('Headers JSON is invalid: ' + e.message); }
|
| 114 |
+
}
|
| 115 |
+
function getSegments(){
|
| 116 |
+
return $('sampleSegments').value.split('\n').map(s => s.trim()).filter(Boolean);
|
| 117 |
+
}
|
| 118 |
+
|
| 119 |
+
async function testManifest(){
|
| 120 |
+
setStatus(manifestStatus,'running','warn');
|
| 121 |
+
const url = getManifest();
|
| 122 |
+
log(`Testing MPD fetch for ${url}`);
|
| 123 |
+
try {
|
| 124 |
+
const res = await fetch(url, { mode:'cors', redirect:'follow', headers:getHeaders() });
|
| 125 |
+
log(`MPD status=${res.status} redirected=${res.redirected} finalURL=${res.url}`);
|
| 126 |
+
log(`MPD content-type=${res.headers.get('content-type')}`);
|
| 127 |
+
log(`MPD access-control-allow-origin=${res.headers.get('access-control-allow-origin')}`);
|
| 128 |
+
const text = await res.text();
|
| 129 |
+
log(`MPD bytes read=${text.length}`);
|
| 130 |
+
log(`MPD first 200 chars=${text.slice(0,200).replace(/\s+/g,' ')}`);
|
| 131 |
+
setStatus(manifestStatus, res.ok ? 'OK' : String(res.status), res.ok ? 'ok' : 'bad');
|
| 132 |
+
} catch (e) {
|
| 133 |
+
log(`MPD fetch failed: ${e.name}: ${e.message}`,'bad');
|
| 134 |
+
setStatus(manifestStatus,'blocked','bad');
|
| 135 |
+
}
|
| 136 |
+
}
|
| 137 |
+
|
| 138 |
+
async function testSegments(){
|
| 139 |
+
const urls = getSegments();
|
| 140 |
+
if (!urls.length) { log('No sample segment URLs provided','bad'); return; }
|
| 141 |
+
setStatus(segmentStatus,'running','warn');
|
| 142 |
+
let ok = 0, partial = 0;
|
| 143 |
+
for (const url of urls) {
|
| 144 |
+
log(`Testing segment ${url}`);
|
| 145 |
+
try {
|
| 146 |
+
const res = await fetch(url, {
|
| 147 |
+
mode:'cors',
|
| 148 |
+
redirect:'follow',
|
| 149 |
+
headers: { ...getHeaders(), 'Range':'bytes=0-1023' }
|
| 150 |
+
});
|
| 151 |
+
const buf = await res.arrayBuffer();
|
| 152 |
+
log(`segment status=${res.status} finalURL=${res.url}`);
|
| 153 |
+
log(`segment content-type=${res.headers.get('content-type')}`);
|
| 154 |
+
log(`segment content-range=${res.headers.get('content-range')}`);
|
| 155 |
+
log(`segment access-control-allow-origin=${res.headers.get('access-control-allow-origin')}`);
|
| 156 |
+
log(`segment bytes read=${buf.byteLength}`);
|
| 157 |
+
if (res.ok) ok++;
|
| 158 |
+
if (res.status === 206) partial++;
|
| 159 |
+
} catch (e) {
|
| 160 |
+
log(`segment fetch failed: ${e.name}: ${e.message}`,'bad');
|
| 161 |
+
}
|
| 162 |
+
}
|
| 163 |
+
if (ok === urls.length && partial === urls.length) setStatus(segmentStatus,'all 206','ok');
|
| 164 |
+
else if (ok > 0) setStatus(segmentStatus,`${ok}/${urls.length} ok`,'warn');
|
| 165 |
+
else setStatus(segmentStatus,'blocked','bad');
|
| 166 |
+
}
|
| 167 |
+
|
| 168 |
+
function destroyPlayer(){
|
| 169 |
+
if (player) {
|
| 170 |
+
try { player.reset(); } catch (_) {}
|
| 171 |
+
player = null;
|
| 172 |
+
}
|
| 173 |
+
playerEl.removeAttribute('src');
|
| 174 |
+
playerEl.load();
|
| 175 |
+
}
|
| 176 |
+
|
| 177 |
+
function startDash(){
|
| 178 |
+
const url = getManifest();
|
| 179 |
+
destroyPlayer();
|
| 180 |
+
setStatus(dashStatus,'starting','warn');
|
| 181 |
+
setStatus(videoStatus,'waiting','warn');
|
| 182 |
+
log(`Initializing dash.js with ${url}`);
|
| 183 |
+
try {
|
| 184 |
+
player = dashjs.MediaPlayer().create();
|
| 185 |
+
player.updateSettings({ debug: { logLevel: dashjs.Debug.LOG_LEVEL_WARNING } });
|
| 186 |
+
player.on(dashjs.MediaPlayer.events.ERROR, (e) => {
|
| 187 |
+
log(`dash.js ERROR type=${e.error || e.event?.id || 'unknown'} message=${e.event?.message || e.message || 'n/a'}`,'bad');
|
| 188 |
+
setStatus(dashStatus,'error','bad');
|
| 189 |
+
});
|
| 190 |
+
player.on(dashjs.MediaPlayer.events.MANIFEST_LOADED, () => {
|
| 191 |
+
log('dash.js MANIFEST_LOADED','ok');
|
| 192 |
+
setStatus(dashStatus,'manifest ok','ok');
|
| 193 |
+
});
|
| 194 |
+
player.on(dashjs.MediaPlayer.events.STREAM_INITIALIZED, () => {
|
| 195 |
+
log('dash.js STREAM_INITIALIZED','ok');
|
| 196 |
+
setStatus(dashStatus,'stream ok','ok');
|
| 197 |
+
});
|
| 198 |
+
playerEl.onloadedmetadata = () => {
|
| 199 |
+
log(`video loaded metadata duration=${Number.isFinite(playerEl.duration) ? playerEl.duration.toFixed(2) : 'unknown'}s currentSrc=${playerEl.currentSrc}`,'ok');
|
| 200 |
+
setStatus(videoStatus,'metadata ok','ok');
|
| 201 |
+
};
|
| 202 |
+
playerEl.oncanplay = () => log('video canplay fired','ok');
|
| 203 |
+
playerEl.onerror = () => {
|
| 204 |
+
const err = playerEl.error;
|
| 205 |
+
log(`video element error code=${err ? err.code : 'unknown'}`,'bad');
|
| 206 |
+
setStatus(videoStatus,'error','bad');
|
| 207 |
+
};
|
| 208 |
+
player.initialize(playerEl, url, false);
|
| 209 |
+
} catch (e) {
|
| 210 |
+
log(`dash.js init failed: ${e.name}: ${e.message}`,'bad');
|
| 211 |
+
setStatus(dashStatus,'init failed','bad');
|
| 212 |
+
}
|
| 213 |
+
}
|
| 214 |
+
|
| 215 |
+
$('testManifest').addEventListener('click', testManifest);
|
| 216 |
+
$('testSegments').addEventListener('click', testSegments);
|
| 217 |
+
$('startDash').addEventListener('click', startDash);
|
| 218 |
+
$('clearLog').addEventListener('click', () => {
|
| 219 |
+
logEl.textContent = '';
|
| 220 |
+
setStatus(manifestStatus,'β');
|
| 221 |
+
setStatus(segmentStatus,'β');
|
| 222 |
+
setStatus(dashStatus,'β');
|
| 223 |
+
setStatus(videoStatus,'β');
|
| 224 |
+
destroyPlayer();
|
| 225 |
+
});
|
| 226 |
+
|
| 227 |
+
log('Ready. Paste your MPD URL and a few sample segment URLs, then run the tests.');
|
| 228 |
+
</script>
|
| 229 |
+
</body>
|
| 230 |
+
</html>
|