story_view icon indicating copy to clipboard operation
story_view copied to clipboard

iOS Failed to load video

Open Quichaco opened this issue 2 years ago • 9 comments

Hello, I have this exception when i play video on iOS only [VERBOSE-2:ui_dart_state.cc(209)] Unhandled Exception: PlatformException(VideoError, Failed to load video: Cannot Open, null, null)

I init the item :

 StoryItem.pageVideo(
            *my_url*,
            controller: storyController,
          )

When I play the same video with the video_player it still works correctly VideoPlayerController.network(**myurl**);

I saw some parts that it could come from the header of the video returned from the server. Here is my header :

Accept-Ranges: bytes
Content-Length: 37622786
Content-Type: application/octet-stream
Date: Sat, 17 Sep 2022 13:01:41 GMT
ETag: "cc865cd42a0f3b1a29ed59d2d5c684f3"
Last-Modified: Sat, 06 Aug 2022 14:21:42 GMT
Server: AmazonS3
x-amz-id-2: ***ID***
x-amz-request-id: ***ID***

This is a known issue ?

Quichaco avatar Sep 17 '22 12:09 Quichaco

@blackmann Can you please take a look at this? this is causing issues for me.

waqadArshad avatar Oct 13 '22 00:10 waqadArshad

Hey, I am having the same issue. Have you got a solution?

Thanks

jerrypaulsam avatar Feb 25 '23 16:02 jerrypaulsam

I was able to resolve this problem by loading the video directly from the url instead of the cached file. The error might be related to the caching in the VideoLoader class [Also, there is an open issue with Flutter itself]. So, for iOS, I am loading the video directly from url and for android from the cached file.

jerrypaulsam avatar Feb 26 '23 04:02 jerrypaulsam

@jerrypaulsam What does that mean, loading the video directly from the url, instead of cached file? How do you load the video "directly"?

In my case, I just pass the media url to StoryItem.pageVideo constructor, but still fails on iOS:

  /// Shorthand for creating page video. [controller] should be same instance as
  /// one passed to the `StoryView`
  factory StoryItem.pageVideo(
    String url, {
    required StoryController controller,
    Key? key,
    Duration? duration,
    BoxFit imageFit = BoxFit.fitWidth,
    String? caption,
    bool shown = false,
    Map<String, dynamic>? requestHeaders,
  }) {
    return StoryItem(
        Container(
          key: key,

How do you load a video from a cache? You do not have access to VideoLoader here.

MartinBergerDX avatar Mar 03 '23 14:03 MartinBergerDX

@MartinBergerDX Hey Martin, We forked the repo and made slight changes to the code.

jerrypaulsam avatar Mar 04 '23 10:03 jerrypaulsam

@jerrypaulsam Thanks for the answer! There are about 50 forks for story_view and I could not find your fork. But does not matter, I fixed it.

I have fixed it by adding ContentType to my files when uploading them with Amplify.Storage category in Flutter.

Future<StorageObject> uploadFile(
      File file,
      String s3Folder,
      List<String>? subfolderPathComponents,
      Map<String, String>? metadata,
      String? contentType,
      Function(double progress)? progressUpdate) async {
    final storageKey = _generateStorageKey(file, subfolderPathComponents);
    final uploadOptions = S3UploadFileOptions(
      accessLevel: StorageAccessLevel.protected,
      metadata: metadata,
      contentType: contentType,
    );
    debugPrint(
        'Beginning file upload with key: $storageKey, s3Folder: ${s3Folder}, subfolderPathComponents: ${subfolderPathComponents.toString()}, metadata: ${metadata.toString()}, contentType: ${contentType}.');
    final UploadFileResult result = await Amplify.Storage.uploadFile(
        local: file,
        key: storageKey,
        options: uploadOptions,
        onProgress: (progressUpdate != null)
            ? (progress) {
                progressUpdate(progress.getFractionCompleted());
              }
            : null);
    debugPrint('Successfully uploaded file with key: ${result.key}');
    final serverUploadStorageKey = _convertToAmplifyStorageKey(s3Folder, storageKey);
    debugPrint('Server upload storage key: $serverUploadStorageKey');
    return StorageObject(
      s3Folder: s3Folder,
      subfolderPathComponents: subfolderPathComponents,
      storageKey: storageKey,
      serverUploadStorageKey: serverUploadStorageKey,
    );
  }

By using S3UploadFileOptions.

final uploadOptions = S3UploadFileOptions(
      accessLevel: StorageAccessLevel.protected,
      metadata: metadata,
      contentType: contentType,
    );

ContentType is set to video/mp4 and when specified here is reflected on S3 in AWS Console. [year 2023]

AWS is making an update for this.

It seems that story_view requires some maintainers, it is awfully forgotten :)

Take care.

MartinBergerDX avatar Mar 07 '23 13:03 MartinBergerDX

any solution please i'm stuck in this problem ?

AliSamir070 avatar Aug 09 '23 13:08 AliSamir070

really very bad support, no update on this issue, many users facing this issue form more than 1 year, they have the new versions but no fix on this issue, also no reply

Kanwarpalsingh1986 avatar Aug 26 '23 06:08 Kanwarpalsingh1986

any updates ?

Obada2020 avatar Dec 31 '23 12:12 Obada2020