Baseflow / flutter_cache_manager

Generic cache manager for flutter
https://baseflow.com
MIT License
740 stars 429 forks source link

How to cooperate with video_player #285

Closed DizzyDuan closed 3 years ago

DizzyDuan commented 3 years ago

💬 Questions and Help

For questions or help we recommend checking:

jenniestrongbow commented 3 years ago

That's a very good question. Why was it closed?

DizzyDuan commented 3 years ago

@jenniestrongbow You can refer to my method

      CacheManager cacheManager = VideoCacheManager.instance;
      FileInfo fileInfo = await cacheManager.getFileFromCache(
        widget.videoUrl,
        ignoreMemCache: true,
      );
      if (fileInfo != null && fileInfo.source == FileSource.Cache) {
        _controller = VideoPlayerController.file(fileInfo.file);
      } else {
        _controller = VideoPlayerController.network(widget.videoUrl);
      }
      await _controller.initialize().then((_) {
        cacheManager.downloadFile(
          widget.videoUrl,
          key: widget.videoUrl,
          force: true,
        );
      });
jenniestrongbow commented 3 years ago

Thanks for the quick reply. Now, how can I stream a video using your cache manager?

I noticed there is a getFileStream method. I suppose it allows viewing a video before it is fully downloaded but I don't know how to use it with video player.

Thanks

DizzyDuan commented 3 years ago

Using flutter_cache_manager plug-in. My plan is to make sure it's completely downloaded. If you want to watch the video before downloading it completely, you need another solution. But also need to consider the cut-off situation, I can not provide you with a solution.

I can provide you with a reference plug-in to see if it is what you need. https://pub.flutter-io.cn/packages/cached_video_player

jenniestrongbow commented 3 years ago

Fair enough. I love your plugin and I understand how it works now. I'll make sure I download the video upfront. Thanks!!!

jenniestrongbow commented 3 years ago

Hi,

CacheManager cacheManager = VideoCacheManager.instance;

VideoCacheManager does not exist. Can you please explain how I can use this?

Thanks

jenniestrongbow commented 3 years ago

I guess it should have been DefaultCacheManager();

DizzyDuan commented 3 years ago
      import 'package:flutter_cache_manager/flutter_cache_manager.dart'
          hide ImageCacheManager;

      export 'package:flutter_cache_manager/flutter_cache_manager.dart'
          hide ImageCacheManager;

      class VideoCacheManager {
        static const key = "anything";
        static CacheManager instance = CacheManager(
          Config(
            key,
            stalePeriod: const Duration(days: 7),
            maxNrOfCacheObjects: 25,
            repo: JsonCacheInfoRepository(databaseName: key),
          ),
        );
      }

You can also use the DefaultCacheManager

jenniestrongbow commented 3 years ago

Thanks a lot!!!!!!!!!!