first step

This commit is contained in:
Page Asgardius 2023-01-02 10:01:59 -07:00
parent 3e67badeb2
commit 3c8d41e05e

View file

@ -41,6 +41,7 @@ import com.google.android.exoplayer2.upstream.cache.LeastRecentlyUsedCacheEvicto
import com.google.android.exoplayer2.upstream.cache.SimpleCache; import com.google.android.exoplayer2.upstream.cache.SimpleCache;
import java.io.File; import java.io.File;
import java.util.ArrayList;
import java.util.Objects; import java.util.Objects;
/** /**
@ -55,6 +56,7 @@ public class VideoPlayer extends AppCompatActivity {
private PowerManager.WakeLock mWakeLock; private PowerManager.WakeLock mWakeLock;
private PowerManager powerManager; private PowerManager powerManager;
private long maxCacheSize; private long maxCacheSize;
ArrayList<String> queue;
LeastRecentlyUsedCacheEvictor evictor; LeastRecentlyUsedCacheEvictor evictor;
StandaloneDatabaseProvider standaloneDatabaseProvider; StandaloneDatabaseProvider standaloneDatabaseProvider;
SimpleCache simpleCache; SimpleCache simpleCache;
@ -70,7 +72,7 @@ public class VideoPlayer extends AppCompatActivity {
AppOpsManager appOpsManager; AppOpsManager appOpsManager;
private PlayerNotificationManager playerNotificationManager; private PlayerNotificationManager playerNotificationManager;
private int notificationId = 1234; private int notificationId = 1234;
boolean hls; boolean isplaylist;
boolean success = false; boolean success = false;
String videoURL, title; String videoURL, title;
Rational ratio; Rational ratio;
@ -103,7 +105,8 @@ public class VideoPlayer extends AppCompatActivity {
title = getIntent().getStringExtra("title"); title = getIntent().getStringExtra("title");
videocache = getIntent().getIntExtra("videocache", 40); videocache = getIntent().getIntExtra("videocache", 40);
buffersize = getIntent().getIntExtra("buffersize", 2000); buffersize = getIntent().getIntExtra("buffersize", 2000);
hls = getIntent().getBooleanExtra("hls", false); isplaylist = getIntent().getBooleanExtra("hls", false);
queue = getIntent().getStringArrayListExtra("queue");
getSupportActionBar().setTitle(title); getSupportActionBar().setTitle(title);
loadControl = new DefaultLoadControl.Builder().setBufferDurationsMs(2000, buffersize, 1500, 2000).build(); loadControl = new DefaultLoadControl.Builder().setBufferDurationsMs(2000, buffersize, 1500, 2000).build();
@ -151,7 +154,7 @@ public class VideoPlayer extends AppCompatActivity {
playerNotificationManager = new PlayerNotificationManager.Builder(this, notificationId, "playback").build(); playerNotificationManager = new PlayerNotificationManager.Builder(this, notificationId, "playback").build();
playerNotificationManager.setMediaSessionToken(mediaSession.getSessionToken()); playerNotificationManager.setMediaSessionToken(mediaSession.getSessionToken());
playerNotificationManager.setPlayer(player); playerNotificationManager.setPlayer(player);
if (hls) { if (title.endsWith(".m3u8")) {
MediaItem mediaItem = MediaItem.fromUri(videoURL); MediaItem mediaItem = MediaItem.fromUri(videoURL);
player.setMediaItem(mediaItem); player.setMediaItem(mediaItem);
} else { } else {
@ -325,7 +328,7 @@ public class VideoPlayer extends AppCompatActivity {
title = intent.getStringExtra("title"); title = intent.getStringExtra("title");
videocache = intent.getIntExtra("videocache", 40); videocache = intent.getIntExtra("videocache", 40);
buffersize = intent.getIntExtra("buffersize", 2000); buffersize = intent.getIntExtra("buffersize", 2000);
hls = intent.getBooleanExtra("hls", false); isplaylist = intent.getBooleanExtra("hls", false);
getSupportActionBar().setTitle(title); getSupportActionBar().setTitle(title);
mediaSource = new ProgressiveMediaSource.Factory( mediaSource = new ProgressiveMediaSource.Factory(
new CacheDataSource.Factory() new CacheDataSource.Factory()
@ -334,7 +337,7 @@ public class VideoPlayer extends AppCompatActivity {
.setUserAgent("ExoplayerDemo")) .setUserAgent("ExoplayerDemo"))
.setFlags(CacheDataSource.FLAG_IGNORE_CACHE_ON_ERROR) .setFlags(CacheDataSource.FLAG_IGNORE_CACHE_ON_ERROR)
).createMediaSource(MediaItem.fromUri(Uri.parse(videoURL))); ).createMediaSource(MediaItem.fromUri(Uri.parse(videoURL)));
if (hls) { if (title.endsWith(".m3u8")) {
MediaItem mediaItem = MediaItem.fromUri(videoURL); MediaItem mediaItem = MediaItem.fromUri(videoURL);
player.setMediaItem(mediaItem); player.setMediaItem(mediaItem);
} else { } else {