package com.offline.music.playermp3.media3;

import android.content.Context;

import androidx.annotation.OptIn;
import androidx.media3.common.util.UnstableApi;
import androidx.media3.database.StandaloneDatabaseProvider;
import androidx.media3.datasource.cache.LeastRecentlyUsedCacheEvictor;
import androidx.media3.datasource.cache.SimpleCache;

import java.io.File;


/**
 * 播放缓存
 */
public class MyPlayCacheManager {

    private static SimpleCache playCache;

    @OptIn(markerClass = UnstableApi.class)
    public static  SimpleCache getInitPlayCache(Context context) {
        if (playCache == null) {
            File cacheDir = new File(context.getCacheDir(), "media_cache");
            long maxCacheSize = 100 * 1024 * 1024;  // 缓存大小 100MB
            StandaloneDatabaseProvider databaseProvider = new  StandaloneDatabaseProvider(context);
            playCache = new SimpleCache(cacheDir, new LeastRecentlyUsedCacheEvictor(maxCacheSize), databaseProvider);
//            MyDownloadService.init(context,databaseProvider);
        }
        return playCache;
    }


}
