HarmonyOS鸿蒙Next中js Fa应用video组件怎么播放本地视频,file:///data/storage/el2/base/haps/entry/files路径下的视频显示 Cannot find base path of data/storage/el2/

HarmonyOS鸿蒙Next中js Fa应用video组件怎么播放本地视频,file:///data/storage/el2/base/haps/entry/files路径下的视频显示 Cannot find base path of data/storage/el2/ 如题:使用video组件播放本地视频,视频时是下载到沙盒路径下file://data/storage/el2/base/haps/entry/files/Blue_Sky_and_Clouds_Timelapse_0892__Videvo_preview.mp4的,但是使用这个路径去读取却显示 Cannot find base path of data/storage/el2/..., img组件使用相同的地址可以成功读取,这是哪里出错了


更多关于HarmonyOS鸿蒙Next中js Fa应用video组件怎么播放本地视频,file:///data/storage/el2/base/haps/entry/files路径下的视频显示 Cannot find base path of data/storage/el2/的实战教程也可以访问 https://www.itying.com/category-93-b0.html

2 回复

在HarmonyOS鸿蒙Next中,使用JS FA应用的video组件播放本地视频时,路径file:///data/storage/el2/base/haps/entry/files无法找到。这是因为鸿蒙系统的安全机制限制了直接访问data/storage/el2路径。正确的做法是使用@ohos.fileio模块提供的API来获取应用沙箱内的文件路径。

首先,确保视频文件已放置在应用的resources/rawfile目录下。然后,使用getContext().resourceManager.getRawFile方法获取文件的路径。示例代码如下:

import fileio from '@ohos.fileio';

let context = getContext(this);
let path = context.resourceManager.getRawFile('your_video_file.mp4');

this.videoSrc = path;

video组件中,将src属性绑定到this.videoSrc

<video src="{{videoSrc}}" controls></video>

更多关于HarmonyOS鸿蒙Next中js Fa应用video组件怎么播放本地视频,file:///data/storage/el2/base/haps/entry/files路径下的视频显示 Cannot find base path of data/storage/el2/的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html


在HarmonyOS鸿蒙Next中,使用<video>组件播放本地视频时,确保视频文件路径正确且应用具有访问权限。file:///data/storage/el2/base/haps/entry/files路径可能无法直接访问,建议将视频文件放置在应用的rawfile目录下,并通过$rawfile('video.mp4')引用。同时,检查应用的权限配置,确保已申请ohos.permission.READ_MEDIA权限。

回到顶部