From 4afe56b13cb99cbc48c04899ffd7709036d795d4 Mon Sep 17 00:00:00 2001 From: Hardcore Sushi Date: Sun, 10 Sep 2023 19:11:45 +0200 Subject: [PATCH] Migrate to AndroidX Media3 --- app/build.gradle | 7 ++++--- .../hardcore/droidfs/file_viewers/AudioPlayer.kt | 5 ++++- .../file_viewers/EncryptedVolumeDataSource.kt | 14 +++++++++----- .../hardcore/droidfs/file_viewers/MediaPlayer.kt | 16 +++++++++++----- .../hardcore/droidfs/file_viewers/VideoPlayer.kt | 6 +++--- .../droidfs/widgets/DoubleTapPlayerView.kt | 4 ++-- .../main/res/layout/activity_audio_player.xml | 4 ++-- ...iew.xml => audio_exo_player_control_view.xml} | 10 +++++----- app/src/main/res/layout/exo_center_controls.xml | 8 ++++---- ...trol_view.xml => exo_player_control_view.xml} | 0 10 files changed, 44 insertions(+), 30 deletions(-) rename app/src/main/res/layout/{audio_exo_styled_player_control_view.xml => audio_exo_player_control_view.xml} (94%) rename app/src/main/res/layout/{exo_styled_player_control_view.xml => exo_player_control_view.xml} (100%) diff --git a/app/build.gradle b/app/build.gradle index 6bd02ed..5c82695 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -118,9 +118,10 @@ dependencies { implementation 'com.github.bumptech.glide:glide:4.15.1' implementation "androidx.biometric:biometric-ktx:1.2.0-alpha05" - def exoplayer_version = "2.19.1" - implementation "com.google.android.exoplayer:exoplayer-core:$exoplayer_version" - implementation "com.google.android.exoplayer:exoplayer-ui:$exoplayer_version" + def media3_version = "1.1.1" + implementation "androidx.media3:media3-exoplayer:$media3_version" + implementation 'androidx.media3:media3-ui:1.1.1' + implementation "androidx.media3:media3-datasource:$media3_version" implementation "androidx.concurrent:concurrent-futures:1.1.0" diff --git a/app/src/main/java/sushi/hardcore/droidfs/file_viewers/AudioPlayer.kt b/app/src/main/java/sushi/hardcore/droidfs/file_viewers/AudioPlayer.kt index dae378f..8f3fe10 100644 --- a/app/src/main/java/sushi/hardcore/droidfs/file_viewers/AudioPlayer.kt +++ b/app/src/main/java/sushi/hardcore/droidfs/file_viewers/AudioPlayer.kt @@ -1,8 +1,11 @@ package sushi.hardcore.droidfs.file_viewers -import com.google.android.exoplayer2.ExoPlayer +import androidx.annotation.OptIn +import androidx.media3.common.util.UnstableApi +import androidx.media3.exoplayer.ExoPlayer import sushi.hardcore.droidfs.databinding.ActivityAudioPlayerBinding +@OptIn(UnstableApi::class) class AudioPlayer: MediaPlayer(){ private lateinit var binding: ActivityAudioPlayerBinding diff --git a/app/src/main/java/sushi/hardcore/droidfs/file_viewers/EncryptedVolumeDataSource.kt b/app/src/main/java/sushi/hardcore/droidfs/file_viewers/EncryptedVolumeDataSource.kt index f89751a..8d1d3ed 100644 --- a/app/src/main/java/sushi/hardcore/droidfs/file_viewers/EncryptedVolumeDataSource.kt +++ b/app/src/main/java/sushi/hardcore/droidfs/file_viewers/EncryptedVolumeDataSource.kt @@ -1,15 +1,19 @@ package sushi.hardcore.droidfs.file_viewers import android.net.Uri -import com.google.android.exoplayer2.C -import com.google.android.exoplayer2.upstream.DataSource -import com.google.android.exoplayer2.upstream.DataSpec -import com.google.android.exoplayer2.upstream.TransferListener +import androidx.media3.common.C +import androidx.annotation.OptIn +import androidx.media3.common.util.UnstableApi +import androidx.media3.datasource.DataSource +import androidx.media3.datasource.DataSpec +import androidx.media3.datasource.TransferListener import sushi.hardcore.droidfs.Constants import sushi.hardcore.droidfs.filesystems.EncryptedVolume import kotlin.math.min -class EncryptedVolumeDataSource(private val encryptedVolume: EncryptedVolume, private val filePath: String): DataSource { +@OptIn(UnstableApi::class) +class EncryptedVolumeDataSource(private val encryptedVolume: EncryptedVolume, private val filePath: String): + DataSource { private var fileHandle = -1L private var fileOffset: Long = 0 private var bytesRemaining: Long = -1 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 e396817..8a14202 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 @@ -1,16 +1,22 @@ package sushi.hardcore.droidfs.file_viewers import android.view.WindowManager -import com.google.android.exoplayer2.* -import com.google.android.exoplayer2.extractor.DefaultExtractorsFactory -import com.google.android.exoplayer2.source.MediaSource -import com.google.android.exoplayer2.source.ProgressiveMediaSource -import com.google.android.exoplayer2.video.VideoSize +import androidx.annotation.OptIn +import androidx.media3.common.MediaItem +import androidx.media3.common.PlaybackException +import androidx.media3.common.Player +import androidx.media3.common.VideoSize +import androidx.media3.common.util.UnstableApi +import androidx.media3.exoplayer.ExoPlayer +import androidx.media3.exoplayer.source.MediaSource +import androidx.media3.exoplayer.source.ProgressiveMediaSource +import androidx.media3.extractor.DefaultExtractorsFactory import sushi.hardcore.droidfs.Constants import sushi.hardcore.droidfs.R import sushi.hardcore.droidfs.widgets.CustomAlertDialogBuilder import java.io.File +@OptIn(UnstableApi::class) abstract class MediaPlayer: FileViewerActivity() { private lateinit var player: ExoPlayer 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 a785aef..a241f6f 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 @@ -3,8 +3,8 @@ package sushi.hardcore.droidfs.file_viewers import android.content.pm.ActivityInfo import android.content.res.Configuration import android.view.View -import com.google.android.exoplayer2.ExoPlayer -import com.google.android.exoplayer2.ui.StyledPlayerView +import androidx.media3.exoplayer.ExoPlayer +import androidx.media3.ui.PlayerView import sushi.hardcore.droidfs.databinding.ActivityVideoPlayerBinding class VideoPlayer: MediaPlayer() { @@ -19,7 +19,7 @@ class VideoPlayer: MediaPlayer() { setContentView(binding.root) applyNavigationBarMargin(binding.root) binding.videoPlayer.doubleTapOverlay = binding.doubleTapOverlay - binding.videoPlayer.setControllerVisibilityListener(StyledPlayerView.ControllerVisibilityListener { visibility -> + binding.videoPlayer.setControllerVisibilityListener(PlayerView.ControllerVisibilityListener { visibility -> binding.topBar.visibility = visibility if (visibility == View.VISIBLE) { showPartialSystemUi() diff --git a/app/src/main/java/sushi/hardcore/droidfs/widgets/DoubleTapPlayerView.kt b/app/src/main/java/sushi/hardcore/droidfs/widgets/DoubleTapPlayerView.kt index e3e37da..7816702 100644 --- a/app/src/main/java/sushi/hardcore/droidfs/widgets/DoubleTapPlayerView.kt +++ b/app/src/main/java/sushi/hardcore/droidfs/widgets/DoubleTapPlayerView.kt @@ -17,14 +17,14 @@ import android.widget.LinearLayout import androidx.core.view.GestureDetectorCompat import androidx.core.view.updateLayoutParams import androidx.core.view.updatePadding -import com.google.android.exoplayer2.ui.StyledPlayerView +import androidx.media3.ui.PlayerView import sushi.hardcore.droidfs.R class DoubleTapPlayerView @JvmOverloads constructor( context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0 -) : StyledPlayerView(context, attrs, defStyleAttr) { +) : PlayerView(context, attrs, defStyleAttr) { companion object { const val SEEK_SECONDS = 10 diff --git a/app/src/main/res/layout/activity_audio_player.xml b/app/src/main/res/layout/activity_audio_player.xml index 967245b..87eb205 100644 --- a/app/src/main/res/layout/activity_audio_player.xml +++ b/app/src/main/res/layout/activity_audio_player.xml @@ -15,11 +15,11 @@ android:textSize="@dimen/title_text_size" android:padding="10dp"/> - diff --git a/app/src/main/res/layout/audio_exo_styled_player_control_view.xml b/app/src/main/res/layout/audio_exo_player_control_view.xml similarity index 94% rename from app/src/main/res/layout/audio_exo_styled_player_control_view.xml rename to app/src/main/res/layout/audio_exo_player_control_view.xml index 7fdd111..5490c99 100644 --- a/app/src/main/res/layout/audio_exo_styled_player_control_view.xml +++ b/app/src/main/res/layout/audio_exo_player_control_view.xml @@ -26,20 +26,20 @@ android:layout_gravity="center_horizontal" android:background="@android:color/transparent" android:gravity="center" - android:layoutDirection="ltr" android:padding="@dimen/exo_styled_controls_padding" - android:layout_marginBottom="-40dp" - android:clipToPadding="false"> + android:clipToPadding="false" + android:layoutDirection="ltr" + android:layout_marginBottom="-40dp"> - + - + diff --git a/app/src/main/res/layout/exo_center_controls.xml b/app/src/main/res/layout/exo_center_controls.xml index b61b0b4..b24827a 100644 --- a/app/src/main/res/layout/exo_center_controls.xml +++ b/app/src/main/res/layout/exo_center_controls.xml @@ -8,19 +8,19 @@ android:layout_gravity="center" android:background="@android:color/transparent" android:gravity="center" - android:layoutDirection="ltr" android:padding="@dimen/exo_styled_controls_padding" - android:clipToPadding="false"> + android:clipToPadding="false" + android:layoutDirection="ltr"> - + - + diff --git a/app/src/main/res/layout/exo_styled_player_control_view.xml b/app/src/main/res/layout/exo_player_control_view.xml similarity index 100% rename from app/src/main/res/layout/exo_styled_player_control_view.xml rename to app/src/main/res/layout/exo_player_control_view.xml