From c340282a8765e390f2498457188d3b02c8e18cf6 Mon Sep 17 00:00:00 2001 From: Hardcore Sushi Date: Mon, 5 Apr 2021 12:42:35 +0200 Subject: [PATCH] Video player screen auto-rotation --- app/build.gradle | 4 ++-- .../hardcore/droidfs/file_viewers/MediaPlayer.kt | 6 ++++++ .../hardcore/droidfs/file_viewers/VideoPlayer.kt | 13 +++++++++++++ app/src/main/res/drawable/icon_screen_rotation.xml | 5 +++++ app/src/main/res/layout/activity_video_player.xml | 4 ++-- app/src/main/res/values-pt-rBR/strings.xml | 2 +- app/src/main/res/values-ru/strings.xml | 2 +- app/src/main/res/values/strings.xml | 4 +++- app/src/main/res/xml/root_preferences.xml | 9 ++++++++- 9 files changed, 41 insertions(+), 8 deletions(-) create mode 100644 app/src/main/res/drawable/icon_screen_rotation.xml diff --git a/app/build.gradle b/app/build.gradle index efa1c94..55ed126 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -15,8 +15,8 @@ android { applicationId "sushi.hardcore.droidfs" minSdkVersion 21 targetSdkVersion 29 - versionCode 12 - versionName "1.4.4" + versionCode 13 + versionName "1.4.5" ndk { abiFilters 'x86_64', 'armeabi-v7a', 'arm64-v8a' diff --git a/app/src/main/java/sushi/hardcore/droidfs/file_viewers/MediaPlayer.kt b/app/src/main/java/sushi/hardcore/droidfs/file_viewers/MediaPlayer.kt index a10f630..b680144 100644 --- a/app/src/main/java/sushi/hardcore/droidfs/file_viewers/MediaPlayer.kt +++ b/app/src/main/java/sushi/hardcore/droidfs/file_viewers/MediaPlayer.kt @@ -27,6 +27,7 @@ abstract class MediaPlayer: FileViewerActivity() { abstract fun bindPlayer(player: SimpleExoPlayer) protected open fun onPlaylistIndexChanged() {} + protected open fun onPlayerReady() {} private fun createMediaSource(filePath: String): MediaSource { val dataSourceFactory = GocryptfsDataSource.Factory(gocryptfsVolume, filePath) @@ -51,6 +52,11 @@ abstract class MediaPlayer: FileViewerActivity() { player.seekToDefaultPosition(currentPlaylistIndex) player.playWhenReady = true player.addListener(object : Player.EventListener{ + override fun onPlayerStateChanged(playWhenReady: Boolean, playbackState: Int) { + if (playbackState == Player.STATE_READY) { + onPlayerReady() + } + } override fun onPlayerError(error: ExoPlaybackException) { if (error.type == ExoPlaybackException.TYPE_SOURCE){ ColoredAlertDialogBuilder(this@MediaPlayer) diff --git a/app/src/main/java/sushi/hardcore/droidfs/file_viewers/VideoPlayer.kt b/app/src/main/java/sushi/hardcore/droidfs/file_viewers/VideoPlayer.kt index 1242f1b..bdcc661 100644 --- a/app/src/main/java/sushi/hardcore/droidfs/file_viewers/VideoPlayer.kt +++ b/app/src/main/java/sushi/hardcore/droidfs/file_viewers/VideoPlayer.kt @@ -1,10 +1,16 @@ package sushi.hardcore.droidfs.file_viewers +import android.content.pm.ActivityInfo import com.google.android.exoplayer2.SimpleExoPlayer import kotlinx.android.synthetic.main.activity_video_player.* import sushi.hardcore.droidfs.R + class VideoPlayer: MediaPlayer() { + private var firstPlay = true + private val autoFit by lazy { + sharedPrefs.getBoolean("autoFit", false) + } override fun viewFile() { setContentView(R.layout.activity_video_player) super.viewFile() @@ -17,4 +23,11 @@ class VideoPlayer: MediaPlayer() { override fun getFileType(): String { return "video" } + + override fun onPlayerReady() { + if (firstPlay && autoFit) { + requestedOrientation = if (video_player.width < video_player.height) ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT else ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE + firstPlay = false + } + } } \ No newline at end of file diff --git a/app/src/main/res/drawable/icon_screen_rotation.xml b/app/src/main/res/drawable/icon_screen_rotation.xml new file mode 100644 index 0000000..66eca5c --- /dev/null +++ b/app/src/main/res/drawable/icon_screen_rotation.xml @@ -0,0 +1,5 @@ + + + diff --git a/app/src/main/res/layout/activity_video_player.xml b/app/src/main/res/layout/activity_video_player.xml index 4a134a0..a9d8b29 100644 --- a/app/src/main/res/layout/activity_video_player.xml +++ b/app/src/main/res/layout/activity_video_player.xml @@ -7,8 +7,8 @@ \ No newline at end of file diff --git a/app/src/main/res/values-pt-rBR/strings.xml b/app/src/main/res/values-pt-rBR/strings.xml index 5c99d90..2130a04 100644 --- a/app/src/main/res/values-pt-rBR/strings.xml +++ b/app/src/main/res/values-pt-rBR/strings.xml @@ -106,7 +106,7 @@ Gerenciar funcionalidades inseguras Des/ativar funcionalidades inseguras UI - Cor do tema + Cor do tema Definir uma cor do tema personalizada DroidFS tentar ser o mais seguro possível. No entanto, a segurança muitas vezes envolve falta de conforto. Por isso o DroidFS oferece funcionalidades inseguras adicionais que você pode des/ativar de acordo com as suas necessidades.\n\nAviso: estas funcionalidades podem ser INSEGURAS. Não as utilize a menos que você saiba exatamente o que está fazendo. É altamente recomendável ler a documentação antes de ativá-las.. Ver funcionalidades inseguras diff --git a/app/src/main/res/values-ru/strings.xml b/app/src/main/res/values-ru/strings.xml index 2d63708..b5554df 100644 --- a/app/src/main/res/values-ru/strings.xml +++ b/app/src/main/res/values-ru/strings.xml @@ -105,7 +105,7 @@ Управление небезопасными функциями Включить/отключить небезопасные функции Интерфейс - Цвет темы + Цвет темы Установить собственный цвет темы DroidFS старается быть максимально безопасным, однако безопасность часто связана с появлением неудобств. Поэтому DroidFS предлагает дополнительные небезопасные функции, которые вы можете включить/отключить в соответствии со своими потребностями.\n\nПредупреждение: эти функции могут быть НЕБЕЗОПАСНЫМИ. Не используйте их, если не уверены в своих действиях. Настоятельно рекомендуется прочитать документацию перед их включением. Посмотреть небезопасные функции diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index b9c94f7..f85754a 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -106,7 +106,7 @@ Manage unsafe features Enable/Disable unsafe features UI - Theme color + Theme color Set a custom theme color DroidFS try to be as secure as possible. However, security often involves lack of comfort. This is why DroidFS offer you additional unsafe features that you can enable/disable according to your needs.\n\nWarning: this features can be UNSAFE. Do not use them unless you know exactly what you are doing. It is highly recommended to read the documentation before enabling them. See unsafe features @@ -192,4 +192,6 @@ Wiping files… Folders first Show folders at the beginning of the list + Video player screen auto-rotation + Auto-rotate the screen to fit video dimensions diff --git a/app/src/main/res/xml/root_preferences.xml b/app/src/main/res/xml/root_preferences.xml index d6d6504..67a93a6 100644 --- a/app/src/main/res/xml/root_preferences.xml +++ b/app/src/main/res/xml/root_preferences.xml @@ -6,7 +6,7 @@ @@ -16,6 +16,13 @@ android:key="resetThemeColor" android:icon="@drawable/icon_restore"/> + +