簡體   English   中英

如何讓 HLS.js 從服務器端獲取數據?

[英]How to let HLS.js fetch data from server side?

我使用 hls.js 來實現我的視頻播放器,我在 https:/// 中有一些 ts 文件和一個 m3u8 文件。

我用php讀取m3u8文件並將內容發送到js(res [“manifest”] = m3u8的內容),然后將其放入hls.loadSource(),如下所示。

var manifest = res["manifest"];
var blob = new Blob([manifest]);
var hls = new Hls();
var url = URL.createObjectURL(blob);

hls.loadSource(url);
hls.attachMedia(video);
hls.on(Hls.Events.MANIFEST_PARSED, function() {
    video.load();
});

在此之后,hls 開始通過以下方式獲取 m3u8 中列出的文件

blob:https://<my domain>/<video name>.mp4

當然,它找不到文件,因為它們在

https://<my domain>/<video name>.mp4

代替

blob:https://<my domain>/<video name>.mp4

請求日志

The url starts with "blob:" is created by URL.createObjectURL in front-end,but now I want that hls sends requests to video.php,then video.php reads the ts files and responses the contents back from server side.

有什么方法可以做到這一點? (修改源代碼,更改設置,...等)

我不敢相信我做到了。

我在下面修改了 src/loader/fragment.ts 的源代碼:

@@ -78,9 +78,7 @@ export class BaseSegment {
 
   get url(): string {
     if (!this._url && this.baseurl && this.relurl) {
-      this._url = buildAbsoluteURL(this.baseurl, this.relurl, {
-        alwaysNormalize: true,
-      });
+      this._url = 'video.php?f=' + this.relurl;
     }
     return this._url || '';
   }

然后用 webpack 重新編譯。 現在它使用查詢參數“f=<video name>.mp4”向video.php發送get請求,所以我可以用我的video.php處理請求。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM