Skip to content

Commit

Permalink
[media-library] Fix getAssetInfoAsync doesn't return localUri for vid…
Browse files Browse the repository at this point in the history
…eos (#5806)

# Why

Resolve #2448.

# How

For video files, to get additional information we need to use `requestAVAssetForVideo` method.

# Test Plan

- https://snack.expo.io/@lukaszkosmaty/medialibrary.getassetinfoasync-does-not-return-localuri-for-mediatype-%22video%22 - now display `local Uri` property for both images and videos.
  • Loading branch information
lukmccall authored and cruzach committed Oct 3, 2019
1 parent a3f25aa commit 8569e42
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 12 deletions.
2 changes: 1 addition & 1 deletion docs/pages/versions/unversioned/sdk/media-library.md
Expand Up @@ -249,7 +249,7 @@ Removes all listeners.
| localUri \* | _string_ | both | Local URI for the asset | |
| location \* | _object_ | both | GPS location if available | `latitude: number, longitude: number` or `null` |
| exif \* | _object_ | both | EXIF metadata associated with the image | |
| orientation \* | _number_ | iOS | Display orientation of the image | Numbers 1-8, see [EXIF orientation specification](http://sylvana.net/jpegcrop/exif_orientation.html) |
| orientation \* | _number_ | iOS | Display orientation of the image. Orientation is available only for assets whose mediaType is MediaType.photo | Numbers 1-8, see [EXIF orientation specification](http://sylvana.net/jpegcrop/exif_orientation.html) |
| isFavorite \* | _boolean_ | iOS | Whether the asset is marked as favorite | `true`, `false` |

> \* These fields can be obtained only by calling `getAssetInfoAsync` method
Expand Down
34 changes: 23 additions & 11 deletions packages/expo-media-library/ios/EXMediaLibrary/EXMediaLibrary.m
Expand Up @@ -388,19 +388,31 @@ - (NSDictionary *)constantsToExport

if (asset) {
NSMutableDictionary *result = [EXMediaLibrary _exportAssetInfo:asset];
PHContentEditingInputRequestOptions *options = [PHContentEditingInputRequestOptions new];
options.networkAccessAllowed = YES;

[asset requestContentEditingInputWithOptions:options completionHandler:^(PHContentEditingInput * _Nullable contentEditingInput, NSDictionary * _Nonnull info) {
result[@"localUri"] = [contentEditingInput.fullSizeImageURL absoluteString];
result[@"orientation"] = @(contentEditingInput.fullSizeImageOrientation);

if (asset.mediaType == PHAssetMediaTypeImage) {
if (asset.mediaType == PHAssetMediaTypeImage) {
PHContentEditingInputRequestOptions *options = [PHContentEditingInputRequestOptions new];
options.networkAccessAllowed = YES;

[asset requestContentEditingInputWithOptions:options
completionHandler:^(PHContentEditingInput * _Nullable contentEditingInput, NSDictionary * _Nonnull info) {
result[@"localUri"] = [contentEditingInput.fullSizeImageURL absoluteString];
result[@"orientation"] = @(contentEditingInput.fullSizeImageOrientation);

CIImage *ciImage = [CIImage imageWithContentsOfURL:contentEditingInput.fullSizeImageURL];
result[@"exif"] = ciImage.properties;
}
resolve(result);
}];
resolve(result);
}];
} else {
PHVideoRequestOptions *options = [PHVideoRequestOptions new];
options.networkAccessAllowed = YES;

[[PHImageManager defaultManager] requestAVAssetForVideo:asset
options:options
resultHandler:^(AVAsset * _Nullable asset, AVAudioMix * _Nullable audioMix, NSDictionary * _Nullable info) {
AVURLAsset *urlAsset = (AVURLAsset *)asset;
result[@"localUri"] = [[urlAsset URL] absoluteString];
resolve(result);
}];
}
} else {
resolve([NSNull null]);
}
Expand Down

0 comments on commit 8569e42

Please sign in to comment.