uni-app 上 Protocol 'https' not on whitelist 'file,crypto'! 如何解决?

发布于 1周前 作者 h691938207 来自 Uni-App

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 | - |

2 回复

问题同:https://ask.dcloud.net.cn/question/181025 官方只改了uniapp x没有uniapp,也是佩服。


在 uni-app 中,如果你遇到 Protocol 'https' not on whitelist 'file,crypto'! 这样的错误,通常是因为你在某些地方尝试使用 https 协议,但 uni-app 的运行环境(如小程序或 H5)对协议有严格的限制。

解决方法:

  1. 检查代码中的 URL: 确保你在代码中使用的 URL 符合 uni-app 支持的协议。例如,如果你在小程序环境中,确保你使用的是 https 协议,而不是 http 或其他协议。

  2. 使用 @/./ 引用本地资源: 如果你在代码中引用本地资源,确保使用相对路径或 @/ 来引用项目中的文件,而不是直接使用 httpshttp 协议。

  3. 配置 manifest.json: 在 uni-app 的 manifest.json 文件中,你可以配置 networkTimeoutrequest 等参数,确保网络请求符合运行环境的要求。

    {
      "networkTimeout": {
        "request": 60000,
        "connectSocket": 60000,
        "uploadFile": 60000,
        "downloadFile": 60000
      },
      "request": {
        "timeout": 60000
      }
    }
  4. 检查运行环境: 如果你在小程序环境中运行,确保你使用的 API 和协议符合小程序的规范。小程序的网络请求通常要求使用 https 协议。

  5. 使用 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);
      }
    });
回到顶部
AI 助手
你好,我是IT营的 AI 助手
您可以尝试点击下方的快捷入口开启体验!