uni-app 上 Protocol 'https' not on whitelist 'file,crypto'! 如何解决?
uni-app 上 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
谢谢
| 开发环境 | 版本号 | 项目创建方式 |
|---------|--------|--------------|
| Windows | Windows 10 | HBuilderX |
| uniapp/App | vue2 | - |
问题同:https://ask.dcloud.net.cn/question/181025
官方只改了uniapp x没有uniapp,也是佩服。
在 uni-app 中,如果你遇到 Protocol 'https' not on whitelist 'file,crypto'!
这样的错误,通常是因为你在某些地方尝试使用 https
协议,但 uni-app 的运行环境(如小程序或 H5)对协议有严格的限制。
解决方法:
-
检查代码中的 URL: 确保你在代码中使用的 URL 符合 uni-app 支持的协议。例如,如果你在小程序环境中,确保你使用的是
https
协议,而不是http
或其他协议。 -
使用
@/
或./
引用本地资源: 如果你在代码中引用本地资源,确保使用相对路径或@/
来引用项目中的文件,而不是直接使用https
或http
协议。 -
配置
manifest.json
: 在 uni-app 的manifest.json
文件中,你可以配置networkTimeout
和request
等参数,确保网络请求符合运行环境的要求。{ "networkTimeout": { "request": 60000, "connectSocket": 60000, "uploadFile": 60000, "downloadFile": 60000 }, "request": { "timeout": 60000 } }
-
检查运行环境: 如果你在小程序环境中运行,确保你使用的 API 和协议符合小程序的规范。小程序的网络请求通常要求使用
https
协议。 -
使用
uni.request
进行网络请求: 如果你需要进行网络请求,建议使用uni.request
方法,并确保 URL 是https
协议的。uni.request({ url: 'https://example.com/api', method: 'GET', success: (res) => { console.log(res.data); }, fail: (err) => { console.error(err); } });