iosfluttervideo-player

video_player package not able to play mp4-files on iOS but android


I am downloading mp4 file from Firestore. Then I sure it in the Cache with the ChaceManager. Like:

 dev.log(name: 'Resource_Explorer', 'Trying to chace Video: $videoName');
      final storageRef = _firebaseStorage.ref(path);
      final fileData = await storageRef.getData();
      return ExplorerFileInfo(await cacheinstance.putFile(path, fileData!, key: path), FileState.downloaded);

Then I provide the Video to my Video Player as:

final videoFile = (await resourceExplorer.getVideoFile(videoPath)).value;

Everything works fine on Android. But on IOS im getting the error:
[VERBOSE-2:dart_vm_initializer.cc(41)] Unhandled Exception: PlatformException(VideoError, Failed to load video: Cannot Open, null, null)

I searched for the error 'Failed to load video: Cannot Open' and found GitHub issue which is still open. but only one person had the same 'Cannot Open' as me. They are getting error like: 'Failed to load video: Operation Stopped,'. And this issue is still unsolved. And seems to be a Http error.

I am able to play the same video from my assets. And I am able to do the same steps to display an Image on IOS and on Android.

I would be greatful for any help. Thanks in advance!


Update:
After I downloaded the file with the Duo package instead of .getData(), I was able to deliver the file as wished mp4 and play it with the video_player.
But if I safe the data in the cache with the cache manager, I will get the data as .file and video_player is not able to play .file files on iOS.


Solution

  • In your case, the issue is that you are not setting the file extension when the file gets saved in the cache.

    The putFile method of the DefaultCacheManager saves sets the file extension to .file by default, this makes it impossible for iOS to play the video.

    The solution is to update the putFile method specifying a fileExtension, like so:

    return ExplorerFileInfo(await cacheinstance.putFile(path, fileData!, key: path, fileExtension: 'mp4'), FileState.downloaded);
    

    This way you don't need to update the file name like you described in your solution.