Fix for videos
This commit is contained in:
parent
129621c73c
commit
a0563ce4c0
|
@ -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);
|
||||
|
|
|
@ -172,6 +172,8 @@ public class LiveNotificationService extends Service implements NetworkStateRece
|
|||
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||
final SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
boolean notify = sharedpreferences.getBoolean(Helper.SET_NOTIFY, true);
|
||||
|
||||
|
||||
if (!notify || intent == null || intent.getBooleanExtra("stop", false)) {
|
||||
totalAccount = 0;
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
|
@ -298,15 +300,13 @@ public class LiveNotificationService extends Service implements NetworkStateRece
|
|||
if (response == null)
|
||||
return;
|
||||
final Notification notification;
|
||||
String dataId;
|
||||
Bundle b = new Bundle();
|
||||
boolean canSendBroadCast = true;
|
||||
Helper.EventStreaming event;
|
||||
final SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
||||
try {
|
||||
switch (response.get("event").toString()) {
|
||||
case "notification":
|
||||
if ("notification".equals(response.get("event").toString())) {
|
||||
eventsCount++;
|
||||
if (Build.VERSION.SDK_INT >= 26) {
|
||||
channel = new NotificationChannel(CHANNEL_ID,
|
||||
|
@ -496,15 +496,6 @@ public class LiveNotificationService extends Service implements NetworkStateRece
|
|||
editor.putString(Helper.LAST_NOTIFICATION_MAX_ID + account.getId() + account.getInstance(), notification.getId());
|
||||
editor.apply();
|
||||
}
|
||||
break;
|
||||
case "delete":
|
||||
event = Helper.EventStreaming.DELETE;
|
||||
try {
|
||||
dataId = response.getString("id");
|
||||
b.putString("dataId", dataId);
|
||||
} catch (JSONException ignored) {
|
||||
}
|
||||
break;
|
||||
}
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
|
@ -520,7 +511,6 @@ public class LiveNotificationService extends Service implements NetworkStateRece
|
|||
for (Thread t : Thread.getAllStackTraces().keySet()) {
|
||||
if (t.getName().startsWith("notif_live_")) {
|
||||
t.interrupt();
|
||||
t = null;
|
||||
}
|
||||
}
|
||||
Thread.currentThread().interrupt();
|
||||
|
|
Loading…
Reference in New Issue