パッケージ、リポジトリ、アプリカテゴリを検索

パッケージ詳細v0.3.1

media_cache_manager

このパッケージは、メディア(音声、動画、画像など)をキャッシュするのを助けます。

AndroidiOSmacOSWindowsLinux
30日間ダウンロード
84
いいね数
84
Pub ポイント
160

パッケージをインストール

flutter pub add media_cache_manager

パッケージ概要

公開情報に基づく選定ガイドです。参考としてご利用ください。

media_cache_manager パッケージは、画像、音声、動画などのメディアファイルを複数のプラットフォームで簡単にかつ効率的にキャッシュする方法を提供します。ダウンロード、保存、メディアの取得を処理し、期限切れまたは使用されていないファイルを自動的にクリーンアップします。パフォーマンスと信頼性を重視して設計されており、同期および非同期操作をサポートしており、リモートソースからメディアコンテンツを頻繁に読み込むアプリに最適です。このパッケージはFlutterのアセットシステムとシームレスに統合され、デバイスストレージの最適な利用を保証します。

用途

  • 画像ギャラリーで画像をキャッシュする
  • オーディオおよびビデオコンテンツのストリーミング
  • 繰り返しメディアのネットワークリクエストを減らす
  • モバイルアプリにおけるオフラインメディアアクセス
  • 大規模なメディアアセットを効率的に管理する

主な機能

  • 複数のメディアタイプ(画像、音声、動画)をサポート
  • キャッシュされたファイルの自動有効期限切れとクリーンアップ
  • クロスプラットフォーム互換性(Android、iOS、macOS、Windows、Linux)
  • ダウンロードおよび取得のためのシンプルなAPI
  • 設定可能なキャッシュサイズと保持ポリシー

適している対象

  • 大量のメディアコンテンツを含むアプリ
  • オフライン優先のアプリケーション
  • メディアストリーミングプラットフォーム
  • 画像中心のソーシャルメディアアプリ
  • 効率的なリソース管理を必要とするアプリケーション

注意事項

  • ストレージの問題を避けるために、キャッシュサイズの慎重な管理が必要です
  • 一部のプラットフォームでは、ファイルシステムへのアクセスに追加の権限が必要になる場合があります
  • カスタム構成なしでは、非常に大きなメディアファイルには最適化されていません
  • 限定された組み込みの分析またはモニタリングツール
  • 高度な機能には外部の依存関係に依存しています

元の README

関連するソースリポジトリの README 原文のスナップショットです。最新の内容はリポジトリをご覧ください。


📦 media_cache_manager

⚡ Helps you to cache and encrypt media (Audio 🎵, Video 🎬, Image 🖼️, etc...) Permanently or for a specific time.

With just a URL, the DownloadMediaBuilder widget will:

  • 🔍 Search locally for the file.
  • 📂 If found → File will be returned in a snapshot.
  • ⬇️ If not found → File will be downloaded and stored locally, then returned in a snapshot.

✨ What’s New?

  • 🗓️ daysToExpire behavior improved.
  • ⚙️ autoDownload option to enable/disable auto download.
  • 📝 Renamed onInit ➝ onInitialize.
  • 🔄 Added initial state to DownloadMediaStatus.
  • 🔐 Encrypt & decrypt files with AES.
  • ⏹️ Cancel downloads anytime.
  • 🔁 Retry failed downloads.
  • 🔄 Added Encrypting / Decrypting states.
  • 🧩 Refactored DownloadMediaBuilder widget.
  • 🚀 Optimized plugin imports.

📥 Install

Add to your pubspec.yaml:

dependencies:
  media_cache_manager: 
⚙️ Android Setup
  1. Open android → app → build.gradle
  2. Add this inside defaultConfig:
multiDexEnabled true
minSdkVersion 20

🚀 Initializing Plugin (Required)

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await MediaCacheManager.instance.init();
  runApp(const MyApp());
}

🔐 Encrypted Files (Optional)

Encrypt media files using AES (OFB mode).

✅ Enable encryption globally
await MediaCacheManager.instance.setEncryptionPassword("I love flutter");

or directly on init:

await MediaCacheManager.instance.init(encryptionPassword: 'I love flutter');

⚠️ Notes:

  • 🐢 Large files may take more time to en/decrypt.
  • 🔒 Files are stored in Temporary Directory, so users & other apps can’t access them.
  • 🔑 Keep passwords safe! The plugin does not cache your file passwords.
🔐 Encrypt single file
DownloadMediaBuilder(
  url: "https://example.com/sample.jpg",
  encryptionPassword: "this is a password",  
  onSuccess: (snapshot) {
    return Image.file(File(snapshot.filePath!));
  }
)

⏳ File Expiration (Optional)

Make cached files expire automatically after specific days.

await MediaCacheManager.instance.setExpireDate(daysToExpire: 10);

or via init:

await MediaCacheManager.instance.init(daysToExpire: 1);

📌 Behavior: If a file is accessed before its expiration → expiration will extend automatically.


⚡ General Usage

DownloadMediaBuilder(
  url: 'https://example.com/sample.jpg',
  onSuccess: (snapshot) {
    return Image.file(File(snapshot.filePath!));
  },
  onLoading: (snapshot) {
    return LinearProgressIndicator(value: snapshot.progress);
  },
),

⏯️ Disable Auto Download

By default, autoDownload = true. You can disable it and control downloads manually:

late DownloadMediaBuilderController controller;

DownloadMediaBuilder(
  url: 'https://example.com/video.mp4',
  autoDownload: false,
  onInitialize: (ctrl) => controller = ctrl,
  onInitial: (_) {
    return ElevatedButton(
      onPressed: controller.getFile,
      child: const Text('Load file'),
    );
  },
  onSuccess: (snapshot) => BetterPlayer.file(snapshot.filePath!),
  onLoading: (snapshot) => LinearProgressIndicator(value: snapshot.progress),
),

⚠️ Handle Loading & Error States

DownloadMediaBuilder(
  url: 'https://example.com/video.mp4',
  onLoading: (snapshot) => LinearProgressIndicator(value: snapshot.progress),
  onSuccess: (snapshot) => BetterPlayer.file(snapshot.filePath!),
  onError: (_) => const Text('❌ Error!'),
),

⏹️ Cancel & 🔄 Retry Downloads

late DownloadMediaBuilderController controller;

DownloadMediaBuilder(
  url: 'https://example.com/video.mp4',
  onInitialize: (ctrl) => controller = ctrl,
  onLoading: (snapshot) {
    return Column(
      children: [
        LinearProgressIndicator(value: snapshot.progress),
        ElevatedButton(
          onPressed: controller.cancel,
          child: const Text('Cancel Download'),
        ),
      ],
    );
  },
  onSuccess: (snapshot) => BetterPlayer.file(snapshot.filePath!),
  onError: (_) => const Text('❌ Error!'),
  onCancel: (_) {
    return ElevatedButton(
      onPressed: controller.retry,
      child: const Text('Retry'),
    );
  },
),

📌 Notes:

  • ❌ You can only call cancel() if status = loading.
  • 🔁 You can only call retry() if status = canceled.

📊 Snapshot Explained

DownloadMediaSnapshot contains 3 fields:

  1. Status → Initial, Success, Loading, Error, Canceled, Encrypting, Decrypting.
  2. FilePath → Available if file is downloaded.
  3. Progress → Download progress (0 → 1).

カテゴリー

依存関係

依存関係一覧 4 件

ソースリポジトリ

このパッケージを使用しているプロジェクト

データはまだありません。