flutter_photo_manager icon indicating copy to clipboard operation
flutter_photo_manager copied to clipboard

[Bug report] cannot access video format in iOS 18 Live Photo

Open dodatw opened this issue 1 year ago • 5 comments

Version

3.5.0

Platforms

iOS

Device Model

iPhone 15 (iOS 18)

flutter info

[✓] Flutter (Channel stable, 3.24.3, on macOS 15.0.1 24A348 darwin-arm64,
    locale zh-Hant-TW)
    • Flutter version 3.24.3 on channel stable at
      /Users/rdapp/fvm/versions/stable
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 2663184aa7 (4 周前), 2024-09-11 16:27:48 -0500
    • Engine revision 36335019a8
    • Dart version 3.5.3
    • DevTools version 2.37.3
    • Pub download mirror http://app-pub-pc01.pft.com:8080

[✓] Android toolchain - develop for Android devices (Android SDK version
    33.0.2)
    • Android SDK at /Users/rdapp/Library/Android/sdk
    • Platform android-34, build-tools 33.0.2
    • Java binary at: /Applications/Android
      Studio.app/Contents/jbr/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build
      17.0.11+0-17.0.11b1207.24-11852314)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 16.0)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 16A242d
    • CocoaPods version 1.15.2

[✓] Android Studio (version 2024.1)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build
      17.0.11+0-17.0.11b1207.24-11852314)

[✓] Connected device (4 available)
    • Pixel 7 (mobile)                • 2A141FDH2003LG            •
      android-arm64 • Android 14 (API 34)
    • Tommy’s iPhone (mobile)         • 00008130-0002212810EB8D3A • ios
      • iOS 18.0.1 22A3370
    • macOS (desktop)                 • macos                     •
      darwin-arm64  • macOS 15.0.1 24A348 darwin-arm64
    • Mac Designed for iPad (desktop) • mac-designed-for-ipad     • darwin
      • macOS 15.0.1 24A348 darwin-arm64

[✓] Network resources
    • All expected network resources are available.

How to reproduce?

After upgrade to iOS 18, I want to Live Photo in video, seem not work anymore.

getMediaUrl => "file:///var/mobile/Media/DCIM/117APPLE/IMG_7666.MOV" Exception when play this video: PlatformException(VideoError, Failed to load video: The file couldn’t be opened because you don’t have permission to view it., null, null)

I also tried fileWithSubtype fileWithSubtype => file: File: '/private/var/mobile/Containers/Data/Application/973F8808-BD05-4354-9C1A-FA9CAC5A3AF9/tmp/.video/A10CB802-AB97-48D3-AF8C-9FB5D270BCBB_L0_001_1728264640.877920_o_IMG_7666.MOV' Exception when play this video: PlatformException(VideoError, Failed to load video: Operation Stopped, null, null)

Is there any special porting need finish in iOS 18? It play normal at iOS 17 (by getMediaUrl)

Logs

No response

Example code (optional)

No response

Contact

No response

dodatw avatar Oct 09 '24 05:10 dodatw

https://github.com/miguelpruivo/flutter_file_picker/issues/612#issuecomment-1831761825

AlexV525 avatar Oct 09 '24 05:10 AlexV525

miguelpruivo/flutter_file_picker#612 (comment)

I think it should be different issue. It still can reproduce after reboot. This issue can reproduce more than one device. All devices are iOS 18.

dodatw avatar Oct 09 '24 06:10 dodatw

We don't have iOS 18 devices around, unfortunately.

AlexV525 avatar Oct 09 '24 07:10 AlexV525

How about video assets? Do they played well on iOS 18?

AlexV525 avatar Oct 09 '24 17:10 AlexV525

How about video assets? Do they played well on iOS 18?

Video Assets can play without issue.

dodatw avatar Oct 10 '24 04:10 dodatw

The video url of live photo is got from the "privateFileURL".

(void)getMediaUrl:(NSString *)assetId
      resultHandler:(NSObject <PMResultHandler> *)handler
    progressHandler:(NSObject <PMProgressHandlerProtocol> *)progressHandler

if (@available(iOS 9.1, *)) {
        if ((asset.mediaSubtypes & PHAssetMediaSubtypePhotoLive) == PHAssetMediaSubtypePhotoLive) {
            PHAssetResource *resource = [asset getLivePhotosResource];
            NSURL *url = [resource valueForKey:@"privateFileURL"];
            if (url) {
                [handler reply:url.absoluteString];
                return;
            }
            [self fetchLivePhotosFile:asset handler:handler progressHandler:progressHandler withScheme:YES fileType:nil];
            return;
        }
    }
...

In iOS 18, if the "privateFileURL" is used to init the AVURLAsset and AVPlayerItem, the status of AVPlayerItem will be always AVPlayerItemStatusFailed and the video can not start to play.

In the other hand, the video url got from the following functions should work.

[self fetchLivePhotosFile:asset handler:handler progressHandler:progressHandler withScheme:YES fileType:nil];

shanxus avatar Oct 29 '24 07:10 shanxus

@dodatw Could you help to confirm if the above comment works in your case?

AlexV525 avatar Oct 29 '24 07:10 AlexV525

Hi Alex,

it is work if I call this function directlly

[self fetchLivePhotosFile:asset handler:handler progressHandler:progressHandler withScheme:YES fileType:nil];

Is it possiable fix in photo_manager ? ex, check if iOS 18 don't call these function

            PHAssetResource *resource = [asset getLivePhotosResource];
            NSURL *url = [resource valueForKey:@"privateFileURL"];
            if (url) {
                [handler reply:url.absoluteString];
                return;
            }

dodatw avatar Oct 29 '24 08:10 dodatw

Please apply the snippet until we fix this in the future release.

// https://github.com/fluttercandies/flutter_photo_manager/issues/1196
if (@available(iOS 18.0, *)) {
    [self fetchLivePhotosFile:asset handler:handler progressHandler:progressHandler withScheme:YES fileType:nil];
    return;
}
PHAssetResource *resource = [asset getLivePhotosResource];
NSURL *url = [resource valueForKey:@"privateFileURL"];
if (url) {
    [handler reply:url.absoluteString];
    return;
}
[self fetchLivePhotosFile:asset handler:handler progressHandler:progressHandler withScheme:YES fileType:nil];
return;

AlexV525 avatar Oct 29 '24 09:10 AlexV525