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
2024-11-12 09:06:39
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
superinsect

getAssets时没有在fetchColumn里面指定key,参考:

fetchColumns: [photoAccessHelper.PhotoKeys.WIDTH, photoAccessHelper.PhotoKeys.HEIGHT, photoAccessHelper.PhotoKeys.TITLE], 

​地址:

https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/js-apis-photoaccesshelper-V5

分享
微博
QQ
微信
回复
2024-11-12 15:24:11
相关问题
HarmonyOS photoAsset获取图片宽高失败
341浏览 • 1回复 待解决
ImageKnife控件会有缓存读取失败
1118浏览 • 1回复 待解决
HarmonyOS调用PhotoAccessHelper.getAssets问题
462浏览 • 1回复 待解决
HarmonyOS java.util.List.size() 报错
199浏览 • 1回复 待解决
使用安装命令报错install invalid hap size
7593浏览 • 1回复 待解决
RichText组件font标签size属性不符合预期
1874浏览 • 1回复 待解决
HarmonyOS如何读取文件
600浏览 • 1回复 待解决
Map对象使用[]赋值,Map中的size不递增
462浏览 • 1回复 待解决