Video player screen auto-rotation

This commit is contained in:
Matéo Duparc 2021-04-05 12:42:35 +02:00
parent f119ccf477
commit c340282a87
Signed by untrusted user: hardcoresushi
GPG Key ID: 007F84120107191E
9 changed files with 41 additions and 8 deletions

View File

@ -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'

View File

@ -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)

View File

@ -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
}
}
}

View File

@ -0,0 +1,5 @@
<vector android:height="24dp" android:tint="#FFFFFF"
android:viewportHeight="24" android:viewportWidth="24"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="@android:color/white" android:pathData="M16.48,2.52c3.27,1.55 5.61,4.72 5.97,8.48h1.5C23.44,4.84 18.29,0 12,0l-0.66,0.03 3.81,3.81 1.33,-1.32zM10.23,1.75c-0.59,-0.59 -1.54,-0.59 -2.12,0L1.75,8.11c-0.59,0.59 -0.59,1.54 0,2.12l12.02,12.02c0.59,0.59 1.54,0.59 2.12,0l6.36,-6.36c0.59,-0.59 0.59,-1.54 0,-2.12L10.23,1.75zM14.83,21.19L2.81,9.17l6.36,-6.36 12.02,12.02 -6.36,6.36zM7.52,21.48C4.25,19.94 1.91,16.76 1.55,13L0.05,13C0.56,19.16 5.71,24 12,24l0.66,-0.03 -3.81,-3.81 -1.33,1.32z"/>
</vector>

View File

@ -7,8 +7,8 @@
<com.google.android.exoplayer2.ui.PlayerView
android:id="@+id/video_player"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"/>
</LinearLayout>

View File

@ -106,7 +106,7 @@
<string name="manage_unsafe_features">Gerenciar funcionalidades inseguras</string>
<string name="manage_unsafe_features_summary">Des/ativar funcionalidades inseguras</string>
<string name="ui">UI</string>
<string name="preference_theme_color_title">Cor do tema</string>
<string name="preference_theme_color">Cor do tema</string>
<string name="preference_theme_color_summary">Definir uma cor do tema personalizada</string>
<string name="usf_home_warning_msg">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..</string>
<string name="see_unsafe_features">Ver funcionalidades inseguras</string>

View File

@ -105,7 +105,7 @@
<string name="manage_unsafe_features">Управление небезопасными функциями</string>
<string name="manage_unsafe_features_summary">Включить/отключить небезопасные функции</string>
<string name="ui">Интерфейс</string>
<string name="preference_theme_color_title">Цвет темы</string>
<string name="preference_theme_color">Цвет темы</string>
<string name="preference_theme_color_summary">Установить собственный цвет темы</string>
<string name="usf_home_warning_msg">DroidFS старается быть максимально безопасным, однако безопасность часто связана с появлением неудобств. Поэтому DroidFS предлагает дополнительные небезопасные функции, которые вы можете включить/отключить в соответствии со своими потребностями.\n\nПредупреждение: эти функции могут быть НЕБЕЗОПАСНЫМИ. Не используйте их, если не уверены в своих действиях. Настоятельно рекомендуется прочитать документацию перед их включением.</string>
<string name="see_unsafe_features">Посмотреть небезопасные функции</string>

View File

@ -106,7 +106,7 @@
<string name="manage_unsafe_features">Manage unsafe features</string>
<string name="manage_unsafe_features_summary">Enable/Disable unsafe features</string>
<string name="ui">UI</string>
<string name="preference_theme_color_title">Theme color</string>
<string name="preference_theme_color">Theme color</string>
<string name="preference_theme_color_summary">Set a custom theme color</string>
<string name="usf_home_warning_msg">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.</string>
<string name="see_unsafe_features">See unsafe features</string>
@ -192,4 +192,6 @@
<string name="file_op_wiping_msg">Wiping files…</string>
<string name="folders_first">Folders first</string>
<string name="folders_first_summary">Show folders at the beginning of the list</string>
<string name="auto_fit_title">Video player screen auto-rotation</string>
<string name="auto_fit_summary">Auto-rotate the screen to fit video dimensions</string>
</resources>

View File

@ -6,7 +6,7 @@
<com.jaredrummler.android.colorpicker.ColorPreferenceCompat
android:defaultValue="@color/themeColor"
android:key="themeColor"
android:title="@string/preference_theme_color_title"
android:title="@string/preference_theme_color"
android:summary="@string/preference_theme_color_summary"
android:icon="@drawable/icon_palette"/>
@ -16,6 +16,13 @@
android:key="resetThemeColor"
android:icon="@drawable/icon_restore"/>
<SwitchPreferenceCompat
android:title="@string/auto_fit_title"
android:summary="@string/auto_fit_summary"
android:key="autoFit"
android:defaultValue="false"
android:icon="@drawable/icon_screen_rotation"/>
</PreferenceCategory>
<PreferenceCategory android:title="@string/explorer">