使用 API 调用和不记名令牌身份验证在 android 中播放视频

问题描述

我正在尝试使用简单的 GET API 和使用 VideoView 在 android 中的承载令牌身份验证播放视频。我尝试了很多方法并通过互联网搜索了很多,但没有任何效果。

我的视频 API 如下所示:https://example.com/api/v1/messages/files/{videoID} 并且我需要在标头中提供一个不记名令牌。

此 API 在响应正文中返回文件,当我在 Postman 中测试时一切正常,我可以在 postman 中播放视频。

但在代码中实现此 API 时,VideoView 无法播放视频。这是我的代码:

fun playVideo() {
        var videoView: VideoView = requireActivity().findViewById(R.id.videoView)
        val mediaController: MediaController
        mediaController = MediaController(activity)
        mediaController.setAnchorView(videoView)
        val header: MutableMap<String,String> = HashMap(1)
        val auth = "Bearer " + token
        header.put("Authorization",auth)
        videoView.setVideoURI(Uri.parse("https://example.com/api/v1/messages/files/{videoID}"),header)
        videoView.start()
        videoView.setMediaController(mediaController)
}

我无法确定此问题是由于身份验证失败还是其他原因引起的。这是我在播放视频时遇到的错误的屏幕截图。

enter image description here

enter image description here

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)