Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
879 views
in Technique[技术] by (71.8m points)

javascript - Load m3u8 video file as Blob with different orign

I'm attempting to stream video using a Blob URL created from an m3u8 URL.

The m3u8 file contains only relative paths.

E.g.

file1.ts
file2.ts
...

The m3u8 file is stored on a separate host (e.g. the URL is fileserver.com/path/thevideo.m3u8) than the website loading the video (e.g. the URL is website.com).

Therefore, after converting the m3u8 URL to a Blob, the video player subsequently looks for:

website.com/file1.ts
website.com/file2.ts

Whereas, the actual URLs are:

fileserver.com/path/file1.ts
fileserver.com/path/file2.ts

Question is, is there any way to get the video player (I'm using VideoJS) to use the correct URL prefix?

The code I used for Blob URL generation is here: set video objects source file to a blob url

I can confirm that it works if the m3u8 file contains the full *.ts URLs instead of the relative paths, but I want to see if this is possible using only the relative path as that would be more convenient.

question from:https://stackoverflow.com/questions/65835994/load-m3u8-video-file-as-blob-with-different-orign

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You can attach a custom handler for requests made by videojs/http-streaming engine.

player.tech().vhs.xhr.beforeRequest = function(options) {
  options.uri = options.uri.replace('example.com', 'foo.com');

  return options;
};

Note: You should make a check with safari hls playback if you're using overrideNative option.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...