갤러리에서 비디오 파일의 너비를 읽을 때 발생하는 크래시 해결 방법

발행: (2026년 1월 12일 오전 11:41 GMT+9)
4 min read
원문: Dev.to

Source: Dev.to

문제 설명

그래픽 노트를 게시할 때, 시스템 앨범에서 이미지 또는 비디오를 선택한 후 시스템 앨범 리소스의 파일 경로를 얻습니다. 게시 과정에서 인터페이스는 이미지/비디오 리소스의 너비와 높이를 조회해야 합니다.

갤러리에서 비디오 파일을 선택하고 다음을 호출하면

photoAccessHelper.PhotoAsset.get(photoAccessHelper.PhotoKeys.WIDTH)

충돌이 발생합니다.

문제 코드

async uriGetAssets() {
  try {
    let phAccessHelper = photoAccessHelper.getPhotoAccessHelper(this.context);
    let predicates = new dataSharePredicates.DataSharePredicates();
    // Configure query conditions, use PhotoViewPicker to select the URI of the image to be queried.
    predicates.equalTo('uri', this.uri);
    let fetchOption = {
      fetchColumns: [],
      predicates: predicates
    };
    let fetchResult = await phAccessHelper.getAssets(fetchOption);
    // Obtain the PhotoAsset object corresponding to the URI and read partial information of the file.
    const asset = await fetchResult.getFirstObject();
    console.info('asset displayName: ', asset.displayName);
    console.info('asset uri: ', asset.uri);
    console.info('asset photoType: ', asset.photoType);
    // The following code will throw an error when trying to get the width and height.
    console.info('asset width: ', asset.get(photoAccessHelper.PhotoKeys.WIDTH));
    console.info('asset height: ', asset.get(photoAccessHelper.PhotoKeys.HEIGHT));
  } catch (error) {
    console.error('uriGetAssets failed with err: ' + JSON.stringify(error));
  }
}

배경 지식

  • photoAccessHelper.PhotoAsset.get 인터페이스 문서.
  • photoAccessHelper.FetchOptions 인터페이스 문서.

문제 해결 과정

오류 코드 14000014는 *“Member is not a valid PhotoKey”*라는 메시지와 일치하며, WIDTHHEIGHTget 메서드에 대한 유효한 키가 아님을 나타냅니다.

가능한 원인:

  1. 비디오 파일을 읽을 수 없어 너비와 높이가 존재하지 않는다.
  2. 너비와 높이를 얻는 방법이 잘못되었다.

비디오가 정상적으로 읽히므로 첫 번째 가능성은 배제됩니다. 문제는 정보 획득 방법에 있습니다.

photoAccessHelper.PhotoAsset.get() 인터페이스는 uri, media_type, subtype, display_name 네 가지 속성만 조회를 지원합니다. 다른 속성을 조회하려면 fetchColumns에 필요한 PhotoKeys를 지정해야 합니다. 예를 들어 title 속성을 가져오려면 fetchColumns: ['title']로 설정합니다.

분석 결론

photoAccessHelper.PhotoAsset.get()은 위 네 속성만 조회할 수 있습니다. 너비와 높이와 같은 다른 속성을 얻으려면 FetchOptionsfetchColumns에 포함시켜야 합니다.

해결책

필요한 속성(width, height, 선택적으로 title)을 FetchOptions 구성 항목의 fetchColumns에 추가합니다.

// Add the properties for width, height and title that need to be obtained in the fetchColumns of the configuration item.
let fetchOption = {
  fetchColumns: ['width', 'height'],
  predicates: predicates
};

이 변경 후, asset 객체에 widthheight 값이 포함되며 충돌 없이 접근할 수 있습니다.

검증 결과

문제가 해결되어 검증되었습니다: 비디오 파일의 너비와 높이가 이제 충돌 없이 올바르게 조회됩니다.

Back to Blog

관련 글

더 보기 »

데이터베이스 트랜잭션 누수

소개 우리는 memory leaks에 대해 자주 이야기하지만, backend development에서 또 다른 조용한 성능 저해 요인이 있습니다: Database Transaction Leaks. 나는 최근에 ...