add hls playback

This commit is contained in:
Page Asgardius 2022-11-25 18:21:05 -07:00
parent 1e61324702
commit 56d17c131b
3 changed files with 21 additions and 5 deletions

View file

@ -204,7 +204,7 @@ public class ObjectSelect extends AppCompatActivity {
Img.add(R.drawable.audiofile);
}
else if(Name.get(i).toString().toLowerCase(Locale.ROOT).endsWith(".mp4") || Name.get(i).toString().toLowerCase(Locale.ROOT).endsWith(".mkv")
|| Name.get(i).toString().endsWith(".webm") || Name.get(i).toString().endsWith(".m4v")) {
|| Name.get(i).toString().endsWith(".webm") || Name.get(i).toString().endsWith(".m4v") || Name.get(i).toString().endsWith(".m3u8")) {
Img.add(R.drawable.videofile);
}
else if (Name.get(i).toString().toLowerCase(Locale.ROOT).endsWith(".htm") || Name.get(i).toString().toLowerCase(Locale.ROOT).endsWith(".html")) {
@ -350,7 +350,7 @@ public class ObjectSelect extends AppCompatActivity {
@Override
public void run() {
// Sending reference and data to Adapter
videoPlayer(objectURL.toString());
videoPlayer(objectURL.toString(), Name.get(position).toString().endsWith(".m3u8"));
}
});
//System.out.println("tree "+treelevel);
@ -452,7 +452,7 @@ public class ObjectSelect extends AppCompatActivity {
}));
}
private void videoPlayer(String url) {
private void videoPlayer(String url, boolean hls) {
try {
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.N
@ -467,12 +467,14 @@ public class ObjectSelect extends AppCompatActivity {
intent.putExtra("video_url", url);
intent.putExtra("videocache", videocache);
intent.putExtra("buffersize", buffersize);
intent.putExtra("hls", hls);
startActivity(intent);
} else {
Intent intent = new Intent(this, VideoPlayer.class);
intent.putExtra("video_url", url);
intent.putExtra("videocache", videocache);
intent.putExtra("buffersize", buffersize);
intent.putExtra("hls", hls);
startActivity(intent);
}
} catch (PackageManager.NameNotFoundException e) {

View file

@ -68,6 +68,7 @@ public class VideoPlayer extends AppCompatActivity {
AppOpsManager appOpsManager;
private PlayerNotificationManager playerNotificationManager;
private int notificationId = 1234;
boolean hls;
@Override
protected void onCreate(Bundle savedInstanceState) {
@ -96,6 +97,7 @@ public class VideoPlayer extends AppCompatActivity {
String videoURL = getIntent().getStringExtra("video_url");
videocache = getIntent().getIntExtra("videocache", 40);
buffersize = getIntent().getIntExtra("buffersize", 2000);
hls = getIntent().getBooleanExtra("hls", false);
loadControl = new DefaultLoadControl.Builder().setBufferDurationsMs(2000, buffersize, 1500, 2000).build();
@DefaultRenderersFactory.ExtensionRendererMode int extensionRendererMode = DefaultRenderersFactory.EXTENSION_RENDERER_MODE_PREFER;
@ -142,7 +144,12 @@ public class VideoPlayer extends AppCompatActivity {
playerNotificationManager = new PlayerNotificationManager.Builder(this, notificationId, "playback").build();
playerNotificationManager.setMediaSessionToken(mediaSession.getSessionToken());
playerNotificationManager.setPlayer(player);
player.setMediaSource(mediaSource);
if (hls) {
MediaItem mediaItem = MediaItem.fromUri(videoURL);
player.setMediaItem(mediaItem);
} else {
player.setMediaSource(mediaSource);
}
player.prepare();
// Start the playback.
player.play();

View file

@ -68,6 +68,7 @@ public class VideoPlayerPip extends AppCompatActivity {
AppOpsManager appOpsManager;
private PlayerNotificationManager playerNotificationManager;
private int notificationId = 1234;
boolean hls;
@Override
protected void onCreate(Bundle savedInstanceState) {
@ -96,6 +97,7 @@ public class VideoPlayerPip extends AppCompatActivity {
String videoURL = getIntent().getStringExtra("video_url");
videocache = getIntent().getIntExtra("videocache", 40);
buffersize = getIntent().getIntExtra("buffersize", 2000);
hls = getIntent().getBooleanExtra("hls", false);
loadControl = new DefaultLoadControl.Builder().setBufferDurationsMs(2000, buffersize, 1500, 2000).build();
@DefaultRenderersFactory.ExtensionRendererMode int extensionRendererMode = DefaultRenderersFactory.EXTENSION_RENDERER_MODE_PREFER;
@ -142,7 +144,12 @@ public class VideoPlayerPip extends AppCompatActivity {
playerNotificationManager = new PlayerNotificationManager.Builder(this, notificationId, "playback").build();
playerNotificationManager.setMediaSessionToken(mediaSession.getSessionToken());
playerNotificationManager.setPlayer(player);
player.setMediaSource(mediaSource);
if (hls) {
MediaItem mediaItem = MediaItem.fromUri(videoURL);
player.setMediaItem(mediaItem);
} else {
player.setMediaSource(mediaSource);
}
player.prepare();
// Start the playback.
player.play();