From 77c895bbf2d52e10741b71d43daaff8aaeafc958 Mon Sep 17 00:00:00 2001
From: Matthieu <24-artectrex@users.noreply.shinice.net>
Date: Thu, 17 Feb 2022 12:08:57 +0100
Subject: [PATCH] Audio and fullscreen video
---
app/src/main/AndroidManifest.xml | 1 +
.../app/posts/MediaViewerActivity.kt | 53 ++++++++++++++++++-
2 files changed, 53 insertions(+), 1 deletion(-)
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 447f538c..cfcdb8c7 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -25,6 +25,7 @@
+ val windowInsetsController = ViewCompat.getWindowInsetsController(window.decorView)
+ if (!fullscreen) {
+ // Configure the behavior of the hidden system bars
+ windowInsetsController?.systemBarsBehavior = WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
+ // Hide both the status bar and the navigation bar
+ windowInsetsController?.show(WindowInsetsCompat.Type.systemBars())
+ supportActionBar?.show()
+ requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
+ } else {
+ // Configure the behavior of the hidden system bars
+ windowInsetsController?.systemBarsBehavior = WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
+ // Hide both the status bar and the navigation bar
+ windowInsetsController?.hide(WindowInsetsCompat.Type.systemBars())
+
+ requestedOrientation =
+ if (mediaPlayer.videoSize.height < mediaPlayer.videoSize.width) {
+ ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE
+ } else {
+ ActivityInfo.SCREEN_ORIENTATION_PORTRAIT
+ }
+ supportActionBar?.hide()
+ }
+ }
+
+ // Configure audio
+ mediaPlayer.setAudioAttributes(AudioAttributesCompat.Builder()
+ .setLegacyStreamType(STREAM_MUSIC)
+ .setUsage(AudioAttributesCompat.USAGE_MEDIA)
+ .setContentType(AudioAttributesCompat.CONTENT_TYPE_MOVIE)
+ .build()
+ )
+
mediaPlayer.prepare()
binding.videoView.setPlayer(mediaPlayer)
@@ -48,4 +89,14 @@ class MediaViewerActivity : BaseActivity() {
// Start actually playing the video
mediaPlayer.play()
}
+
+ override fun onPause() {
+ super.onPause()
+ mediaPlayer.pause()
+ }
+
+ override fun onDestroy() {
+ super.onDestroy()
+ mediaPlayer.close()
+ }
}
\ No newline at end of file