31 楼正确 你只需要重写 class CustomFragmentLoader extends Hls.DefaultConfig.loader 的 load 方法就行了
load(context, config, callbacks) {
const onSuccessOriginal = callbacks.onSuccess;
callbacks.onSuccess = (response, stats, context) => {
if (context.frag && context.frag.url && context.frag.url.includes('.ts')) {
const encryptedData = new Uint8Array(response.data);
const filenameBase = this.extractFilename(context.frag.url);
const decryptedData = xorDecrypt(encryptedData, this.keyBytes);
response.data = decryptedData.buffer;
}
onSuccessOriginal(response, stats, context);
};
super.load(context, config, callbacks);
} |