HarmonyOS photoAsset读取photoAccessHelper.PhotoKeys.SIZE失败
当我用phAccessHelper.getAssets读取媒体文件后,再用photoAsset读取媒体信息时失败,报错如下:size is err = 14000014; err message: member not exist,但是我看api介绍里是可以的。代码如下:
async readMedia(){
let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates();
// 排序
predicates.orderByDesc(photoAccessHelper.PhotoKeys.DATE_MODIFIED)
let fetchOptions: photoAccessHelper.FetchOptions = {
fetchColumns: [],
predicates: predicates,
};
try {
let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOptions);
// let photoAsset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject();
fetchResult.getAllObjects().then((photoAssets: photoAccessHelper.PhotoAsset[])=>{
photoAssets.forEach((photoAsset: photoAccessHelper.PhotoAsset)=>{
console.info('getAssets photoAsset.uri : ' + photoAsset.uri);
console.info('getAssets displayName = ', photoAsset.displayName);
this.getAssets(photoAsset, photoAccessHelper.PhotoKeys.TITLE)
this.getAssets(photoAsset, photoAccessHelper.PhotoKeys.PHOTO_TYPE)
this.getAssets(photoAsset, photoAccessHelper.PhotoKeys.DISPLAY_NAME)
this.getAssets(photoAsset, photoAccessHelper.PhotoKeys.SIZE)
this.getAssets(photoAsset, photoAccessHelper.PhotoKeys.DURATION)
this.getAssets(photoAsset, photoAccessHelper.PhotoKeys.DATE_ADDED)
this.getAssets(photoAsset, photoAccessHelper.PhotoKeys.DATE_MODIFIED)
this.getAssets(photoAsset, photoAccessHelper.PhotoKeys.DATE_TAKEN)
this.getAssets(photoAsset, photoAccessHelper.PhotoKeys.WIDTH)
this.getAssets(photoAsset, photoAccessHelper.PhotoKeys.HEIGHT)
// 图片
if (photoAsset.photoType === photoAccessHelper.PhotoType.IMAGE){
this.data.push({
itemType: MediaItemType.IMAGE,
urlType: MediaType.LOCAL,
url: photoAsset.uri
})
}else if(photoAsset.photoType === photoAccessHelper.PhotoType.VIDEO){
// 视频
photoAsset.getThumbnail((err, pixelMap) => {
if (err === undefined) {
console.info('getThumbnail successful ' + pixelMap);
this.data.push({
itemType: MediaItemType.VIDEO,
urlType: MediaType.LOCAL,
url: photoAsset.uri,
thumbnailPixMap: pixelMap
})
} else {
console.error(`getThumbnail fail with error: ${err.code}, ${err.message}`);
}
});
}
this.testFetchMetadataFromDataSrc(photoAsset.uri)
})
})
fetchResult.close();
} catch (err) {
console.error('getAssets failed with err: ' + err);
}
}
api介绍如下:
/**
* Returns the value of the specified member.
*
* @param { string } member - Photo asset member. for example : get(PhotoKeys.SIZE)
* @returns { MemberType } Returns the value of the specified photo asset member
* @throws { BusinessError } 401 - if parameter is invalid
* @throws { BusinessError } 13900020 - Invalid argument
* @throws { BusinessError } 14000014 - Member is not a valid PhotoKey
* @syscap SystemCapability.FileManagement.PhotoAccessHelper.Core
* @since 10
*/
get(member: string): MemberType;
HarmonyOS
赞
收藏 0
回答 1
待解决
相关问题
HarmonyOS photoAccessHelper.PhotoAsset set 支持哪些?
355浏览 • 0回复 待解决
HarmonyOS photoAccessHelper.PhotoAsset获取录屏时长不精确
237浏览 • 1回复 待解决
HarmonyOS photoAsset获取图片宽高失败
341浏览 • 1回复 待解决
ImageKnife控件会有缓存读取失败
1118浏览 • 1回复 待解决
HarmonyOS调用PhotoAccessHelper.getAssets问题
462浏览 • 1回复 待解决
HarmonyOS TextDecoder读取超长文件字节流失败
320浏览 • 1回复 待解决
HarmonyOS java.util.List.size() 报错
199浏览 • 1回复 待解决
KVManager 存储数据后,启动 App 读取失败
230浏览 • 1回复 待解决
HarmonyOS升级最新API并集成har之后读取media失败
353浏览 • 1回复 待解决
HarmonyOS 如何实时监听NavPathStack的size的变化?
0浏览 • 0回复 待解决
HarmonyOS photoAccessHelper 相册管理模块的使用
323浏览 • 1回复 待解决
HarmonyOS 中photoAccessHelper获取图片大小报错
520浏览 • 1回复 待解决
根据TS侧传入的模型路径读取模型权重失败
1737浏览 • 1回复 待解决
HarmonyOS photoAccessHelper如何获取所有相册的信息
554浏览 • 1回复 待解决
HarmonyOS photoAccessHelper 获取的图片资源无法获取图像宽高
236浏览 • 1回复 待解决
HarmonyOS photoAccessHelper 能否通过 uri 获取对应的图片obj
362浏览 • 1回复 待解决
使用安装命令报错install invalid hap size
7593浏览 • 1回复 待解决
RichText组件font标签size属性不符合预期
1874浏览 • 1回复 待解决
HarmonyOS如何读取文件
600浏览 • 1回复 待解决
HarmonyOS 图片裁切的接口区域设置,x,y,size是什么单位?
0浏览 • 0回复 待解决
Map对象使用[]赋值,Map中的size不递增
462浏览 • 1回复 待解决
HarmonyOS photoAccessHelper获取到的图片资源,有对应的uuid获取吗
458浏览 • 1回复 待解决
为什么数据库插入回调中显示数据插入成功,读取却失败了?
408浏览 • 1回复 待解决
getAssets时没有在fetchColumn里面指定key,参考:
地址:
https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/js-apis-photoaccesshelper-V5