패키지, 저장소 및 앱 카테고리 검색

패키지 상세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 개

소스 저장소

이 패키지를 사용하는 프로젝트

아직 데이터가 없습니다.