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 支持哪些?
266浏览 • 0回复 待解决
HarmonyOS photoAccessHelper.PhotoAsset获取录屏时长不精确
65浏览 • 1回复 待解决
HarmonyOS photoAsset获取图片宽高失败
227浏览 • 1回复 待解决
ImageKnife控件会有缓存读取失败
954浏览 • 1回复 待解决
HarmonyOS调用PhotoAccessHelper.getAssets问题
352浏览 • 1回复 待解决
HarmonyOS TextDecoder读取超长文件字节流失败
154浏览 • 1回复 待解决
HarmonyOS java.util.List.size() 报错
89浏览 • 1回复 待解决
KVManager 存储数据后,启动 App 读取失败
90浏览 • 1回复 待解决
HarmonyOS升级最新API并集成har之后读取media失败
265浏览 • 1回复 待解决
HarmonyOS photoAccessHelper 相册管理模块的使用
61浏览 • 1回复 待解决
HarmonyOS 中photoAccessHelper获取图片大小报错
355浏览 • 1回复 待解决
HarmonyOS photoAccessHelper如何获取所有相册的信息
414浏览 • 1回复 待解决
根据TS侧传入的模型路径读取模型权重失败
1638浏览 • 1回复 待解决
HarmonyOS photoAccessHelper 获取的图片资源无法获取图像宽高
58浏览 • 1回复 待解决
HarmonyOS photoAccessHelper 能否通过 uri 获取对应的图片obj
256浏览 • 1回复 待解决
使用安装命令报错install invalid hap size
7464浏览 • 1回复 待解决
HarmonyOS如何读取文件
372浏览 • 1回复 待解决
RichText组件font标签size属性不符合预期
1770浏览 • 1回复 待解决
Map对象使用[]赋值,Map中的size不递增
366浏览 • 1回复 待解决
HarmonyOS photoAccessHelper获取到的图片资源,有对应的uuid获取吗
303浏览 • 1回复 待解决
为什么数据库插入回调中显示数据插入成功,读取却失败了?
309浏览 • 1回复 待解决
HarmonyOS 读取raw文件参考示例
361浏览 • 1回复 待解决
HarmonyOS 文件上传 & 资源读取问题
333浏览 • 1回复 待解决
getAssets时没有在fetchColumn里面指定key,参考:
地址:
https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/js-apis-photoaccesshelper-V5