mirror of
https://github.com/antebudimir/tempus.git
synced 2025-12-31 09:33:33 +00:00
TEST - Added media cache in exoplayer
This commit is contained in:
parent
1c6b8024b9
commit
0b57cd3176
4 changed files with 30 additions and 2 deletions
|
|
@ -32,8 +32,8 @@ public class MultiPlayer implements Playback {
|
|||
|
||||
private final Context context;
|
||||
private final SimpleExoPlayer exoPlayer;
|
||||
private final SimpleCache simpleCache;
|
||||
|
||||
private SimpleCache simpleCache;
|
||||
private PlaybackCallbacks callbacks;
|
||||
|
||||
private final ExoPlayer.EventListener eventListener = new ExoPlayer.EventListener() {
|
||||
|
|
@ -94,9 +94,11 @@ public class MultiPlayer implements Playback {
|
|||
|
||||
public MultiPlayer(Context context) {
|
||||
this.context = context;
|
||||
setSimpleCache(context);
|
||||
|
||||
// Create a read-only cache data source factory using the download cache.
|
||||
DataSource.Factory cacheDataSourceFactory = new CacheDataSource.Factory()
|
||||
.setCache(simpleCache)
|
||||
.setCache(DownloadUtil.getDownloadCache(context))
|
||||
.setUpstreamDataSourceFactory(DownloadUtil.getHttpDataSourceFactory(context))
|
||||
.setCacheWriteDataSinkFactory(null); // Disable writing.
|
||||
|
|
@ -115,7 +117,9 @@ public class MultiPlayer implements Playback {
|
|||
|
||||
exoPlayer.addListener(eventListener);
|
||||
exoPlayer.prepare();
|
||||
}
|
||||
|
||||
private void setSimpleCache(Context context) {
|
||||
long cacheSize = PreferenceUtil.getInstance(context).getMediaCacheSize();
|
||||
LeastRecentlyUsedCacheEvictor recentlyUsedCache = new LeastRecentlyUsedCacheEvictor(cacheSize);
|
||||
ExoDatabaseProvider databaseProvider = new ExoDatabaseProvider(context);
|
||||
|
|
@ -168,7 +172,6 @@ public class MultiPlayer implements Playback {
|
|||
@Override
|
||||
public boolean isPlaying() {
|
||||
return exoPlayer.getPlayWhenReady() && exoPlayer.getPlaybackSuppressionReason() == Player.PLAYBACK_SUPPRESSION_REASON_NONE;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -29,4 +29,19 @@
|
|||
<item>200000000</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="pref_media_cache_size_titles">
|
||||
<item>Unlimited</item>
|
||||
<item>2GB</item>
|
||||
<item>1GB</item>
|
||||
<item>400MB</item>
|
||||
<item>200MB</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="pref_media_cache_size_values">
|
||||
<item>4000000000</item>
|
||||
<item>2000000000</item>
|
||||
<item>1000000000</item>
|
||||
<item>400000000</item>
|
||||
<item>200000000</item>
|
||||
</string-array>
|
||||
</resources>
|
||||
|
|
@ -5,6 +5,7 @@
|
|||
<string name="search_hint">Search title, artists or albums</string>
|
||||
<string name="theme_selection">Choose theme</string>
|
||||
<string name="covers_cache">Covers cache</string>
|
||||
<string name="media_cache">Media cache</string>
|
||||
<string name="library_menu_label">Library</string>
|
||||
<string name="home_menu_label">Home</string>
|
||||
<string name="search_menu_label">Search</string>
|
||||
|
|
|
|||
|
|
@ -10,6 +10,15 @@
|
|||
app:title="@string/covers_cache"
|
||||
app:useSimpleSummaryProvider="true" />
|
||||
|
||||
<ListPreference
|
||||
app:defaultValue="400000000"
|
||||
app:dialogTitle="@string/media_cache"
|
||||
app:entries="@array/pref_media_cache_size_titles"
|
||||
app:entryValues="@array/pref_media_cache_size_values"
|
||||
app:key="media_cache_size"
|
||||
app:title="@string/media_cache"
|
||||
app:useSimpleSummaryProvider="true" />
|
||||
|
||||
<ListPreference
|
||||
app:defaultValue="default"
|
||||
app:dialogTitle="@string/theme_selection"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue