uni-app中【报Bug】Protocol 'https' not on whitelist 'file,crypto'! 如何解决?
uni-app中【报Bug】Protocol ‘https’ not on whitelist ‘file,crypto’! 如何解决?
操作步骤:
- 将video组件src设置为本地地址:
static/index.m3u8
index.m3u8
包含网络地址:https://s5.bfzycdn.com/video/shihengxiongjianzhizuiyusha/HD/0001189.ts
预期结果:
- video组件能正常播放视频。
实际结果:
- 手机播放时报错如下:
11-06 16:02:08.049 4030 4367 I IJKMEDIA: Opening 'https://s5.bfzycdn.com/video/shihengxiongjianzhizuiyusha/HD/0001189.ts' for reading 11-06 16:02:08.049 4030 4367 E IJKMEDIA: Protocol 'https' not on whitelist 'file,crypto'! 11-06 16:02:08.049 4030 4367 W IJKMEDIA: Failed to open segment 1197 of playlist 0
bug描述:
手机播放本地m3u8文件报错如下,如何解决?
11-06 16:02:08.049 4030 4367 I IJKMEDIA: Opening 'https://s5.bfzycdn.com/video/shihengxiongjianzhizuiyusha/HD/0001189.ts' for reading
11-06 16:02:08.049 4030 4367 E IJKMEDIA: Protocol 'https' not on whitelist 'file,crypto'!
11-06 16:02:08.049 4030 4367 W IJKMEDIA: Failed to open segment 1197 of playlist 0
谢谢
| 项目 | 值 |
|--------------|-------------|
| 产品分类 | uni-app x/App |
| PC开发环境操作系统 | Windows |
| PC开发环境操作系统版本号 | Windows 10 |
| HBuilderX版本号 | 3.97 |
| 手机系统 | Android |
| 手机系统版本号 | Android 13 |
| 手机机型 | NR21 |
3 回复
看一下index.m3u8这个文件
@DCloud_Android_YJC 见附件。文件没有问题,问题应该在于 底层 ijkplayer库播放不了带有网络地址的m3u8文件。在一些Android播放器里没有问题。
在 uni-app 中,如果你遇到 Protocol 'https' not on whitelist 'file,crypto'!
的错误,通常是因为你在某些环境下(如 H5 或小程序)使用了 https
协议,但该协议不在允许的协议白名单中。
解决方法
1. 检查运行环境
- 如果你在 H5 环境中运行,确保你的代码中使用了正确的协议。H5 环境通常支持
http
和https
协议。 - 如果你在小程序环境中运行,小程序可能不支持直接使用
https
协议,或者需要在小程序的配置文件中进行额外的配置。
2. 修改协议
- 如果你确定不需要使用
https
协议,可以将https
改为http
。 - 如果你必须使用
https
协议,请确保你的运行环境支持该协议。
3. 配置白名单
- 如果你在小程序环境中运行,可以在
manifest.json
或小程序的配置文件中添加https
协议到白名单中。
例如,在 manifest.json
中配置:
{
"mp-weixin": {
"networkTimeout": {
"request": 60000,
"connectSocket": 60000,
"uploadFile": 60000,
"downloadFile": 60000
},
"permission": {
"scope.userLocation": {
"desc": "你的位置信息将用于小程序位置接口的效果展示"
}
},
"requiredBackgroundModes": ["location"],
"plugins": {},
"usingComponents": {},
"navigateToMiniProgramAppIdList": [],
"network": {
"request": {
"domain": [
"https://your-domain.com"
]
}
}
}
}
4. 使用 uni.request
- 如果你在使用
uni.request
进行网络请求,确保你使用的是正确的 URL 和协议。
例如:
uni.request({
url: 'https://your-domain.com/api',
method: 'GET',
success: (res) => {
console.log(res.data);
},
fail: (err) => {
console.error(err);
}
});