Display file name on video player

This commit is contained in:
Matéo Duparc 2022-03-05 19:23:48 +01:00
parent 71a314b0a0
commit bea0906f65
Signed by: hardcoresushi
GPG Key ID: AFE384344A45E13A
6 changed files with 49 additions and 34 deletions

View File

@ -2,7 +2,6 @@ package sushi.hardcore.droidfs.file_viewers
import com.google.android.exoplayer2.ExoPlayer
import sushi.hardcore.droidfs.databinding.ActivityAudioPlayerBinding
import java.io.File
class AudioPlayer: MediaPlayer(){
private lateinit var binding: ActivityAudioPlayerBinding
@ -11,7 +10,6 @@ class AudioPlayer: MediaPlayer(){
binding = ActivityAudioPlayerBinding.inflate(layoutInflater)
setContentView(binding.root)
super.viewFile()
refreshFileName()
}
override fun getFileType(): String {
@ -22,17 +20,7 @@ class AudioPlayer: MediaPlayer(){
binding.audioController.player = player
}
override fun onPlaylistIndexChanged() {
refreshFileName()
}
private fun refreshFileName() {
val filename = File(filePath).name
val pos = filename.lastIndexOf('.')
binding.musicTitle.text = if (pos != -1){
filename.substring(0,pos)
} else {
filename
}
override fun onNewFileName(fileName: String) {
binding.musicTitle.text = fileName
}
}

View File

@ -9,6 +9,7 @@ import com.google.android.exoplayer2.video.VideoSize
import sushi.hardcore.droidfs.ConstValues
import sushi.hardcore.droidfs.R
import sushi.hardcore.droidfs.widgets.CustomAlertDialogBuilder
import java.io.File
abstract class MediaPlayer: FileViewerActivity() {
private lateinit var player: ExoPlayer
@ -16,10 +17,11 @@ abstract class MediaPlayer: FileViewerActivity() {
override fun viewFile() {
supportActionBar?.hide()
initializePlayer()
refreshFileName()
}
abstract fun bindPlayer(player: ExoPlayer)
protected open fun onPlaylistIndexChanged() {}
abstract fun onNewFileName(fileName: String)
protected open fun onVideoSizeChanged(width: Int, height: Int) {}
private fun createMediaSource(filePath: String): MediaSource {
@ -60,7 +62,7 @@ abstract class MediaPlayer: FileViewerActivity() {
override fun onPositionDiscontinuity(reason: Int) {
if (player.currentMediaItemIndex != currentPlaylistIndex) {
playlistNext(player.currentMediaItemIndex == (currentPlaylistIndex+1) % mappedPlaylist.size)
onPlaylistIndexChanged()
refreshFileName()
}
}
})
@ -73,4 +75,8 @@ abstract class MediaPlayer: FileViewerActivity() {
player.release()
}
}
private fun refreshFileName() {
onNewFileName(File(filePath).name)
}
}

View File

@ -21,7 +21,7 @@ class VideoPlayer: MediaPlayer() {
binding.videoPlayer.player = player
binding.videoPlayer.doubleTapOverlay = binding.doubleTapOverlay
binding.videoPlayer.setControllerVisibilityListener { visibility ->
binding.rotateButton.visibility = visibility
binding.topBar.visibility = visibility
}
binding.rotateButton.setOnClickListener {
requestedOrientation =
@ -33,6 +33,10 @@ class VideoPlayer: MediaPlayer() {
}
override fun onNewFileName(fileName: String) {
binding.textFileName.text = fileName
}
override fun getFileType(): String {
return "video"
}

View File

@ -1,7 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/root_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/fullScreenBackgroundColor">
@ -17,8 +15,8 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_margin="20dp"
android:orientation="horizontal">
android:layout_marginHorizontal="20dp"
android:layout_marginTop="10dp">
<TextView
android:id="@+id/text_filename"
@ -26,7 +24,7 @@
android:layout_height="wrap_content"
android:singleLine="true"
android:ellipsize="end"
android:textSize="20sp"
android:textSize="@dimen/title_file_name_text_size"
android:layout_alignParentStart="true"
android:layout_toStartOf="@id/image_delete"
android:layout_centerVertical="true"/>

View File

@ -1,10 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:gravity="center"
android:layoutDirection="ltr"
android:background="@color/fullScreenBackgroundColor">
<FrameLayout
@ -26,12 +24,32 @@
</FrameLayout>
<RelativeLayout
android:id="@+id/top_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginStart="20dp">
<TextView
android:id="@+id/text_file_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:singleLine="true"
android:ellipsize="end"
android:textSize="@dimen/title_file_name_text_size"
android:layout_alignParentStart="true"
android:layout_toStartOf="@id/rotate_button"
android:layout_centerVertical="true"/>
<ImageButton
android:id="@+id/rotate_button"
style="@style/ExoMediaButton"
android:layout_gravity="top|end"
android:layout_marginTop="15dp"
android:src="@drawable/icon_screen_rotation"
app:tint="@color/neutralIconTint"/>
app:tint="@color/neutralIconTint"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"/>
</FrameLayout>
</RelativeLayout>
</RelativeLayout>

View File

@ -11,4 +11,5 @@
<dimen name="dialog_horizontal_padding">30dp</dimen>
<dimen name="dialog_padding_top">10dp</dimen>
<dimen name="dialog_text_size">16sp</dimen>
<dimen name="title_file_name_text_size">20sp</dimen>
</resources>