dlxj commited on
Commit
ae559e0
·
1 Parent(s): 2021b5e

实现了本地 ts 单个视频播放,不依赖 node server

Browse files
Files changed (4) hide show
  1. core.js +46 -0
  2. index.html +4 -0
  3. package-lock.json +61 -1
  4. package.json +2 -1
core.js CHANGED
@@ -5,6 +5,7 @@
5
  const spinner = document.getElementById("spinner");
6
  const channelsContainer = document.getElementById("channelsContainer");
7
  const fileInput = document.getElementById("m3uFile");
 
8
 
9
  let channels = []; // Array degli elementi canale
10
  let currentSelectedIndex = -1;
@@ -106,6 +107,51 @@
106
  };
107
  reader.readAsText(file);
108
  });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
109
 
110
  function updateSelection() {
111
  channels.forEach((channel, index) => {
 
5
  const spinner = document.getElementById("spinner");
6
  const channelsContainer = document.getElementById("channelsContainer");
7
  const fileInput = document.getElementById("m3uFile");
8
+ const tsInput = document.getElementById("tsFile");
9
 
10
  let channels = []; // Array degli elementi canale
11
  let currentSelectedIndex = -1;
 
107
  };
108
  reader.readAsText(file);
109
  });
110
+
111
+ // Event listener per il file input TS: trasforma il file locale in MP4 tramite mux.js e lo riproduce
112
+ tsInput.addEventListener("change", function(event) {
113
+ const file = event.target.files[0];
114
+ if (!file) return;
115
+
116
+ // Reset player
117
+ if (hls) {
118
+ hls.destroy();
119
+ hls = null;
120
+ }
121
+
122
+ // Crea un transmuxer MP4
123
+ const transmuxer = new muxjs.mp4.Transmuxer();
124
+ const reader = new FileReader();
125
+
126
+ reader.onload = function(e) {
127
+ const data = new Uint8Array(e.target.result);
128
+
129
+ // Setup MediaSource
130
+ const mime = 'video/mp4; codecs="avc1.42E01E,mp4a.40.2"';
131
+ const mediaSource = new MediaSource();
132
+ video.src = URL.createObjectURL(mediaSource);
133
+
134
+ mediaSource.addEventListener('sourceopen', function() {
135
+ const sourceBuffer = mediaSource.addSourceBuffer(mime);
136
+
137
+ // Quando mux.js ha dei dati pronti
138
+ transmuxer.on('data', (segment) => {
139
+ const data = new Uint8Array(segment.initSegment.byteLength + segment.data.byteLength);
140
+ data.set(segment.initSegment, 0);
141
+ data.set(segment.data, segment.initSegment.byteLength);
142
+ sourceBuffer.appendBuffer(data);
143
+ });
144
+
145
+ // Invia i dati al transmuxer
146
+ transmuxer.push(data);
147
+ transmuxer.flush();
148
+ });
149
+
150
+ video.play().catch(console.error);
151
+ };
152
+
153
+ reader.readAsArrayBuffer(file);
154
+ });
155
 
156
  function updateSelection() {
157
  channels.forEach((channel, index) => {
index.html CHANGED
@@ -6,6 +6,8 @@
6
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
7
  <!-- Include HLS.js via CDN -->
8
  <script src="https://cdn.jsdelivr.net/npm/hls.js@latest"></script>
 
 
9
  <!-- Custom CSS -->
10
  <link rel="stylesheet" href="style.css">
11
  </head>
@@ -18,6 +20,8 @@
18
  <div class="file-input">
19
  <p>Upload the .m3u or .m3u8 file of your IPTV channels:</p>
20
  <input type="file" id="m3uFile" accept=".m3u, .m3u8">
 
 
21
  <p>(You can interact with the player using mouse, touch, keyboard, gamepad, or remote control).</p>
22
  </div>
23
  <div class="main-container">
 
6
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
7
  <!-- Include HLS.js via CDN -->
8
  <script src="https://cdn.jsdelivr.net/npm/hls.js@latest"></script>
9
+ <!-- Include mux.js for client-side transmuxing -->
10
+ <script src="./node_modules/mux.js/dist/mux.min.js"></script>
11
  <!-- Custom CSS -->
12
  <link rel="stylesheet" href="style.css">
13
  </head>
 
20
  <div class="file-input">
21
  <p>Upload the .m3u or .m3u8 file of your IPTV channels:</p>
22
  <input type="file" id="m3uFile" accept=".m3u, .m3u8">
23
+ <p>Or select a local .ts file to play directly:</p>
24
+ <input type="file" id="tsFile" accept=".ts">
25
  <p>(You can interact with the player using mouse, touch, keyboard, gamepad, or remote control).</p>
26
  </div>
27
  <div class="main-container">
package-lock.json CHANGED
@@ -9,7 +9,17 @@
9
  "version": "1.0.0",
10
  "license": "ISC",
11
  "dependencies": {
12
- "express": "^5.2.1"
 
 
 
 
 
 
 
 
 
 
13
  }
14
  },
15
  "node_modules/accepts": {
@@ -153,6 +163,11 @@
153
  "node": ">= 0.8"
154
  }
155
  },
 
 
 
 
 
156
  "node_modules/dunder-proto": {
157
  "version": "1.0.1",
158
  "resolved": "https://registry.npmjs.org/dunder-proto/-/dunder-proto-1.0.1.tgz",
@@ -355,6 +370,16 @@
355
  "node": ">= 0.4"
356
  }
357
  },
 
 
 
 
 
 
 
 
 
 
358
  "node_modules/gopd": {
359
  "version": "1.2.0",
360
  "resolved": "https://registry.npmjs.org/gopd/-/gopd-1.2.0.tgz",
@@ -503,12 +528,38 @@
503
  "url": "https://opencollective.com/express"
504
  }
505
  },
 
 
 
 
 
 
 
 
 
506
  "node_modules/ms": {
507
  "version": "2.1.3",
508
  "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz",
509
  "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==",
510
  "license": "MIT"
511
  },
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
512
  "node_modules/negotiator": {
513
  "version": "1.0.0",
514
  "resolved": "https://registry.npmjs.org/negotiator/-/negotiator-1.0.0.tgz",
@@ -570,6 +621,15 @@
570
  "url": "https://opencollective.com/express"
571
  }
572
  },
 
 
 
 
 
 
 
 
 
573
  "node_modules/proxy-addr": {
574
  "version": "2.0.7",
575
  "resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-2.0.7.tgz",
 
9
  "version": "1.0.0",
10
  "license": "ISC",
11
  "dependencies": {
12
+ "express": "^5.2.1",
13
+ "mux.js": "^6.3.0"
14
+ }
15
+ },
16
+ "node_modules/@babel/runtime": {
17
+ "version": "7.28.6",
18
+ "resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.28.6.tgz",
19
+ "integrity": "sha512-05WQkdpL9COIMz4LjTxGpPNCdlpyimKppYNoJ5Di5EUObifl8t4tuLuUBBZEpoLYOmfvIWrsp9fCl0HoPRVTdA==",
20
+ "license": "MIT",
21
+ "engines": {
22
+ "node": ">=6.9.0"
23
  }
24
  },
25
  "node_modules/accepts": {
 
163
  "node": ">= 0.8"
164
  }
165
  },
166
+ "node_modules/dom-walk": {
167
+ "version": "0.1.2",
168
+ "resolved": "https://registry.npmjs.org/dom-walk/-/dom-walk-0.1.2.tgz",
169
+ "integrity": "sha512-6QvTW9mrGeIegrFXdtQi9pk7O/nSK6lSdXW2eqUspN5LWD7UTji2Fqw5V2YLjBpHEoU9Xl/eUWNpDeZvoyOv2w=="
170
+ },
171
  "node_modules/dunder-proto": {
172
  "version": "1.0.1",
173
  "resolved": "https://registry.npmjs.org/dunder-proto/-/dunder-proto-1.0.1.tgz",
 
370
  "node": ">= 0.4"
371
  }
372
  },
373
+ "node_modules/global": {
374
+ "version": "4.4.0",
375
+ "resolved": "https://registry.npmjs.org/global/-/global-4.4.0.tgz",
376
+ "integrity": "sha512-wv/LAoHdRE3BeTGz53FAamhGlPLhlssK45usmGFThIi4XqnBmjKQ16u+RNbP7WvigRZDxUsM0J3gcQ5yicaL0w==",
377
+ "license": "MIT",
378
+ "dependencies": {
379
+ "min-document": "^2.19.0",
380
+ "process": "^0.11.10"
381
+ }
382
+ },
383
  "node_modules/gopd": {
384
  "version": "1.2.0",
385
  "resolved": "https://registry.npmjs.org/gopd/-/gopd-1.2.0.tgz",
 
528
  "url": "https://opencollective.com/express"
529
  }
530
  },
531
+ "node_modules/min-document": {
532
+ "version": "2.19.2",
533
+ "resolved": "https://registry.npmjs.org/min-document/-/min-document-2.19.2.tgz",
534
+ "integrity": "sha512-8S5I8db/uZN8r9HSLFVWPdJCvYOejMcEC82VIzNUc6Zkklf/d1gg2psfE79/vyhWOj4+J8MtwmoOz3TmvaGu5A==",
535
+ "license": "MIT",
536
+ "dependencies": {
537
+ "dom-walk": "^0.1.0"
538
+ }
539
+ },
540
  "node_modules/ms": {
541
  "version": "2.1.3",
542
  "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz",
543
  "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==",
544
  "license": "MIT"
545
  },
546
+ "node_modules/mux.js": {
547
+ "version": "6.3.0",
548
+ "resolved": "https://registry.npmjs.org/mux.js/-/mux.js-6.3.0.tgz",
549
+ "integrity": "sha512-/QTkbSAP2+w1nxV+qTcumSDN5PA98P0tjrADijIzQHe85oBK3Akhy9AHlH0ne/GombLMz1rLyvVsmrgRxoPDrQ==",
550
+ "license": "Apache-2.0",
551
+ "dependencies": {
552
+ "@babel/runtime": "^7.11.2",
553
+ "global": "^4.4.0"
554
+ },
555
+ "bin": {
556
+ "muxjs-transmux": "bin/transmux.js"
557
+ },
558
+ "engines": {
559
+ "node": ">=8",
560
+ "npm": ">=5"
561
+ }
562
+ },
563
  "node_modules/negotiator": {
564
  "version": "1.0.0",
565
  "resolved": "https://registry.npmjs.org/negotiator/-/negotiator-1.0.0.tgz",
 
621
  "url": "https://opencollective.com/express"
622
  }
623
  },
624
+ "node_modules/process": {
625
+ "version": "0.11.10",
626
+ "resolved": "https://registry.npmjs.org/process/-/process-0.11.10.tgz",
627
+ "integrity": "sha512-cdGef/drWFoydD1JsMzuFf8100nZl+GT+yacc2bEced5f9Rjk4z+WtFUTBu9PhOi9j/jfmBPu0mMEY4wIdAF8A==",
628
+ "license": "MIT",
629
+ "engines": {
630
+ "node": ">= 0.6.0"
631
+ }
632
+ },
633
  "node_modules/proxy-addr": {
634
  "version": "2.0.7",
635
  "resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-2.0.7.tgz",
package.json CHANGED
@@ -15,6 +15,7 @@
15
  "author": "",
16
  "license": "ISC",
17
  "dependencies": {
18
- "express": "^5.2.1"
 
19
  }
20
  }
 
15
  "author": "",
16
  "license": "ISC",
17
  "dependencies": {
18
+ "express": "^5.2.1",
19
+ "mux.js": "^6.3.0"
20
  }
21
  }