Commit a0563ce4 authored by Thomas's avatar Thomas
Browse files

Fix for videos

parent 129621c7
Pipeline #302395 passed with stage
in 9 minutes and 22 seconds
......@@ -559,7 +559,7 @@ public class PeertubeActivity extends BaseActivity implements OnRetrievePeertube
videoSource = new ProgressiveMediaSource.Factory(dataSourceFactory)
.createMediaSource(Uri.parse(apiResponse.getPeertubes().get(0).getFileUrl(null, apiResponse.getPeertubes().get(0).isStreamService())));
} else {
CacheDataSourceFactory cacheDataSourceFactory = new CacheDataSourceFactory(PeertubeActivity.this, video_cache * 1024 * 1024, 5 * 1024 * 1024);
CacheDataSourceFactory cacheDataSourceFactory = new CacheDataSourceFactory(PeertubeActivity.this);
videoSource = new ProgressiveMediaSource.Factory(cacheDataSourceFactory)
.createMediaSource(Uri.parse(apiResponse.getPeertubes().get(0).getFileUrl(null, apiResponse.getPeertubes().get(0).isStreamService())));
}
......@@ -767,7 +767,7 @@ public class PeertubeActivity extends BaseActivity implements OnRetrievePeertube
videoSource = new ProgressiveMediaSource.Factory(dataSourceFactory)
.createMediaSource(Uri.parse(peertube.getFileUrl(res, peertube.isStreamService())));
} else {
CacheDataSourceFactory cacheDataSourceFactory = new CacheDataSourceFactory(PeertubeActivity.this, video_cache * 1024 * 1024, 5 * 1024 * 1024);
CacheDataSourceFactory cacheDataSourceFactory = new CacheDataSourceFactory(PeertubeActivity.this);
videoSource = new ProgressiveMediaSource.Factory(cacheDataSourceFactory)
.createMediaSource(Uri.parse(peertube.getFileUrl(res, peertube.isStreamService())));
}
......
......@@ -263,7 +263,7 @@ public class MediaSliderFragment extends Fragment implements MediaPlayer.OnCompl
videoSource = new ProgressiveMediaSource.Factory(dataSourceFactory)
.createMediaSource(uri);
} else {
CacheDataSourceFactory cacheDataSourceFactory = new CacheDataSourceFactory(context, video_cache * 1024 * 1024, 5 * 1024 * 1024);
CacheDataSourceFactory cacheDataSourceFactory = new CacheDataSourceFactory(context);
videoSource = new ProgressiveMediaSource.Factory(cacheDataSourceFactory)
.createMediaSource(uri);
}
......
......@@ -18,15 +18,15 @@ import java.io.File;
public class CacheDataSourceFactory implements DataSource.Factory {
private static SimpleCache sDownloadCache;
private final Context context;
private final DefaultDataSourceFactory defaultDatasourceFactory;
private final long maxFileSize, maxCacheSize;
private final long maxFileSize;
public CacheDataSourceFactory(Context context, long maxCacheSize, long maxFileSize) {
public CacheDataSourceFactory(Context context) {
super();
this.context = context;
this.maxCacheSize = maxCacheSize;
this.maxFileSize = maxFileSize;
this.maxFileSize = 5 * 1024 * 1024;
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
String userAgent = sharedpreferences.getString(Helper.SET_CUSTOM_USER_AGENT, Helper.USER_AGENT);
DefaultBandwidthMeter.Builder bandwidthMeterBuilder = new DefaultBandwidthMeter.Builder(context);
......@@ -36,11 +36,19 @@ public class CacheDataSourceFactory implements DataSource.Factory {
new DefaultHttpDataSourceFactory(userAgent, bandwidthMeter));
}
public static SimpleCache getInstance(Context context) {
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
int video_cache = sharedpreferences.getInt(Helper.SET_VIDEO_CACHE, Helper.DEFAULT_VIDEO_CACHE_MB);
LeastRecentlyUsedCacheEvictor evictor = new LeastRecentlyUsedCacheEvictor(video_cache * 1024 * 1024);
ExoDatabaseProvider exoDatabaseProvider = new ExoDatabaseProvider(context);
if (sDownloadCache == null)
sDownloadCache = new SimpleCache(new File(context.getCacheDir(), "media"), evictor, exoDatabaseProvider);
return sDownloadCache;
}
@Override
public DataSource createDataSource() {
LeastRecentlyUsedCacheEvictor evictor = new LeastRecentlyUsedCacheEvictor(maxCacheSize);
ExoDatabaseProvider exoDatabaseProvider = new ExoDatabaseProvider(context);
SimpleCache simpleCache = new SimpleCache(new File(context.getCacheDir(), "media"), evictor, exoDatabaseProvider);
SimpleCache simpleCache = getInstance(context);
return new CacheDataSource(simpleCache, defaultDatasourceFactory.createDataSource(),
new FileDataSource(), new CacheDataSink(simpleCache, maxFileSize),
CacheDataSource.FLAG_BLOCK_ON_CACHE | CacheDataSource.FLAG_IGNORE_CACHE_ON_ERROR, null);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment