From 56d17c131b3c1d09e863638d2db3d37371a8c263 Mon Sep 17 00:00:00 2001 From: Page Asgardius Date: Fri, 25 Nov 2022 18:21:05 -0700 Subject: [PATCH] add hls playback --- .../main/java/asgardius/page/s3manager/ObjectSelect.java | 8 +++++--- .../main/java/asgardius/page/s3manager/VideoPlayer.java | 9 ++++++++- .../java/asgardius/page/s3manager/VideoPlayerPip.java | 9 ++++++++- 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/asgardius/page/s3manager/ObjectSelect.java b/app/src/main/java/asgardius/page/s3manager/ObjectSelect.java index 34219a5..3354221 100644 --- a/app/src/main/java/asgardius/page/s3manager/ObjectSelect.java +++ b/app/src/main/java/asgardius/page/s3manager/ObjectSelect.java @@ -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) { diff --git a/app/src/main/java/asgardius/page/s3manager/VideoPlayer.java b/app/src/main/java/asgardius/page/s3manager/VideoPlayer.java index 31f73c9..f582d9e 100644 --- a/app/src/main/java/asgardius/page/s3manager/VideoPlayer.java +++ b/app/src/main/java/asgardius/page/s3manager/VideoPlayer.java @@ -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(); diff --git a/app/src/main/java/asgardius/page/s3manager/VideoPlayerPip.java b/app/src/main/java/asgardius/page/s3manager/VideoPlayerPip.java index b5c56f1..169a7bd 100644 --- a/app/src/main/java/asgardius/page/s3manager/VideoPlayerPip.java +++ b/app/src/main/java/asgardius/page/s3manager/VideoPlayerPip.java @@ -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();