blackmann / story_view

Story view for apps with stories.
BSD 3-Clause "New" or "Revised" License
402 stars 327 forks source link

iOS Failed to load video #148

Open Quichaco opened 1 year ago

Quichaco commented 1 year ago

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 ?

waqadArshad commented 1 year ago

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

jerrypaulsam commented 1 year ago

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

Thanks

jerrypaulsam commented 1 year ago

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.

MartinBergerDX commented 1 year ago

@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.

jerrypaulsam commented 1 year ago

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

MartinBergerDX commented 1 year ago

@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.

AliSamir070 commented 11 months ago

any solution please i'm stuck in this problem ?

Kanwarpalsingh1986 commented 11 months ago

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

Obada2020 commented 6 months ago

any updates ?