cached_video_player_plus icon indicating copy to clipboard operation
cached_video_player_plus copied to clipboard

iOS playback failed

Open tudosxxx opened this issue 1 year ago • 9 comments

Some logs printed from URLs end in .bin when saved on the phone, and some end in .mp4. If the log ends in .bin, it cannot be played.

tudosxxx avatar Aug 08 '24 07:08 tudosxxx

flutter: Cached video of [https://cdn.xxxx.top/SocialFit/post/SnapVid.Net_3241856401650611273.mp4] is: /var/mobile/Containers/Data/Application/DB92663F-B5FA-4A42-A254-F970651F9D08/Library/Caches/libCachedVideoPlayerPlusData/b93e1750-5555-11ef-9065-0bc8c40944f8.mp4

flutter: Cached video of [https://cdn.fxxxxx.top/SocialFit/post/1723092727753_15116.mp4] is: /var/mobile/Containers/Data/Application/DB92663F-B5FA-4A42-A254-F970651F9D08/Library/Caches/libCachedVideoPlayerPlusData/af07f490-5555-11ef-9065-0bc8c40944f8.bin

tudosxxx avatar Aug 08 '24 07:08 tudosxxx

Are only selected urls being cached as .bin files or any file is cached as .bin?

Also can you just try with the video_player plugin and see if all your urls work properly there?

OutdatedGuy avatar Aug 09 '24 13:08 OutdatedGuy

i am also getting url end with c8c40944f8.bin in ios real device, in android working fine. while caching video its save with c8c40944f8.bin. can you help me out why is it happend?

hasuwebforest avatar Aug 23 '24 14:08 hasuwebforest

@hasuwebforest Can you try with video_player as mentioned in this comment.

OutdatedGuy avatar Sep 16 '24 09:09 OutdatedGuy

@OutdatedGuy Same problem here, only IOS files caches with .bin enviroment. Furthermore, I added the code below where it expects the video to be downloaded from the network when the .bin file is received and it also doesn't work, no download from the network.

if (cachedFile!.file.path.contains('.bin')){
        isCacheAvailable = false;
      }

      realDataSource = isCacheAvailable
          ? Uri.file(cachedFile.file.path).toString()
          : dataSource;

With a normal video_player everything works stably!!!

chahohbily avatar Sep 21 '24 18:09 chahohbily

This can solve your problem:
dependency_overrides: flutter_cache_manager: git: url: https://github.com/Oliver-WJ/flutter_cache_manager.git path: flutter_cache_manager

Oliver-WJ avatar Oct 30 '24 02:10 Oliver-WJ

#54

Musaddiq625 avatar Dec 05 '24 10:12 Musaddiq625

I checked the flutter_cache_manager code and it is setting the file extension using the contentType header. I don't think there is much to do if you don't have control of the server. We are trying to fix the issue on server side and I'll report back the result when done.

If you need the details, I left a comment on the relevant issue in flutter_cache_manager repo:

guneyozsan avatar Jan 09 '25 00:01 guneyozsan

We fixed this by setting the header on the server as video/mp4.

guneyozsan avatar Feb 24 '25 11:02 guneyozsan

It appears the root of this issue lies within the flutter_cache_manager package, which is beyond my direct control to fix.

If you're encountering this problem, here are two potential workarounds:

1. If you own the content server

You can resolve this by configuring your server to correctly set the Content-Type header in its responses. This header is crucial for determining the file extension. For more details, refer to these comments: comment 1 and comment 2.

2. If you don't own or cannot configure the content server

You can override the flutter_cache_manager dependency to use a community-contributed fix. Add the following to your pubspec.yaml file:

dependencies:
  cached_video_player_plus: ^3.0.3

dependency_overrides:
  flutter_cache_manager:
    git:
      url: https://github.com/Oliver-WJ/flutter_cache_manager.git
      path: flutter_cache_manager

While these workarounds don't guarantee a 100% fix, they should significantly mitigate the issue until a proper solution is implemented in the underlying package.

OutdatedGuy avatar Jul 08 '25 21:07 OutdatedGuy

@OutdatedGuy There are exposed methods and getters inside flutter_cache_manager where I think you can define a simple extension method and override its behavior to preserve the file extension.
The only part that needs to be simulated (based on how this library works) is managing the CacheObject

Here is a similar extension method (though it’s not ideal in this case, as it renames the file after it has already been saved with a .bin extension). It should at least give the idea: https://github.com/Baseflow/flutter_cache_manager/issues/405#issuecomment-3325784285

I didn’t have time to fully explore how the default download method creates the CacheObject, but I believe it’s possible to mock that and save it with the correct extension directly.

This way, there’s no need to use a dependency override anymore.

AliAzizi avatar Sep 23 '25 23:09 AliAzizi