Upgrade ExoPlayer to 2.17.1 (#116)

* Upgrade ExoPlayer to 2.17.1

* Upgrade ExoPlayer FFmpeg extension to 2.17.1

* Revert subtitle and audio track buttons changes

* Clean up layout files and code

* Clean up activity_player.xml

* Fix warnings about exo drawables overrides
This commit is contained in:
Jarne Demeulemeester 2022-05-09 21:22:59 +02:00 committed by GitHub
parent f26cf2cf1a
commit b50b7b985f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 103 additions and 90 deletions

View file

@ -113,7 +113,7 @@ dependencies {
kapt("com.google.dagger:hilt-compiler:$hiltVersion")
// ExoPlayer
val exoplayerVersion = "2.16.1"
val exoplayerVersion = "2.17.1"
implementation("com.google.android.exoplayer:exoplayer-core:$exoplayerVersion")
implementation("com.google.android.exoplayer:exoplayer-ui:$exoplayerVersion")
implementation(files("libs/extension-ffmpeg-release.aar"))

View file

@ -10,7 +10,7 @@ import android.widget.TextView
import androidx.activity.viewModels
import androidx.navigation.navArgs
import com.google.android.exoplayer2.C
import com.google.android.exoplayer2.SimpleExoPlayer
import com.google.android.exoplayer2.ExoPlayer
import com.google.android.exoplayer2.ui.TrackSelectionDialogBuilder
import dagger.hilt.android.AndroidEntryPoint
import dev.jdtech.jellyfin.databinding.ActivityPlayerBinding
@ -64,9 +64,9 @@ class PlayerActivity : BasePlayerActivity() {
val videoNameTextView = binding.playerView.findViewById<TextView>(R.id.video_name)
viewModel.currentItemTitle.observe(this, { title ->
viewModel.currentItemTitle.observe(this) { title ->
videoNameTextView.text = title
})
}
val audioButton = binding.playerView.findViewById<ImageButton>(R.id.btn_audio_track)
val subtitleButton = binding.playerView.findViewById<ImageButton>(R.id.btn_subtitle)
@ -89,7 +89,7 @@ class PlayerActivity : BasePlayerActivity() {
"trackselectiondialog"
)
}
is SimpleExoPlayer -> {
is ExoPlayer -> {
val mappedTrackInfo =
viewModel.trackSelector.currentMappedTrackInfo ?: return@setOnClickListener
@ -120,7 +120,7 @@ class PlayerActivity : BasePlayerActivity() {
"trackselectiondialog"
)
}
is SimpleExoPlayer -> {
is ExoPlayer -> {
val mappedTrackInfo =
viewModel.trackSelector.currentMappedTrackInfo ?: return@setOnClickListener
@ -152,7 +152,7 @@ class PlayerActivity : BasePlayerActivity() {
)
}
viewModel.fileLoaded.observe(this, {
viewModel.fileLoaded.observe(this) {
if (it) {
audioButton.isEnabled = true
audioButton.imageAlpha = 255
@ -161,13 +161,13 @@ class PlayerActivity : BasePlayerActivity() {
speedButton.isEnabled = true
speedButton.imageAlpha = 255
}
})
}
viewModel.navigateBack.observe(this, {
viewModel.navigateBack.observe(this) {
if (it) {
onBackPressed()
}
})
}
viewModel.initializePlayer(args.items)
hideSystemUI()

View file

@ -9,7 +9,7 @@ import android.view.View
import android.view.WindowManager.LayoutParams.BRIGHTNESS_OVERRIDE_FULL
import android.view.WindowManager.LayoutParams.BRIGHTNESS_OVERRIDE_OFF
import com.google.android.exoplayer2.ui.AspectRatioFrameLayout
import com.google.android.exoplayer2.ui.PlayerView
import com.google.android.exoplayer2.ui.StyledPlayerView
import dev.jdtech.jellyfin.PlayerActivity
import timber.log.Timber
import kotlin.math.abs
@ -17,7 +17,7 @@ import kotlin.math.abs
class PlayerGestureHelper(
private val appPreferences: AppPreferences,
private val activity: PlayerActivity,
private val playerView: PlayerView,
private val playerView: StyledPlayerView,
private val audioManager: AudioManager
) {
@ -44,7 +44,7 @@ class PlayerGestureHelper(
override fun onSingleTapUp(e: MotionEvent?): Boolean {
playerView.apply {
if (!isControllerVisible) showController() else hideController()
if (!isControllerFullyVisible) showController() else hideController()
}
return true
}

View file

@ -6,11 +6,12 @@
android:layout_height="match_parent"
tools:context=".PlayerActivity">
<com.google.android.exoplayer2.ui.PlayerView
<com.google.android.exoplayer2.ui.StyledPlayerView
android:id="@+id/player_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/black"
app:animation_enabled="false"
app:show_buffering="always" />
<LinearLayout
@ -18,12 +19,13 @@
android:layout_width="64dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|start"
android:layout_margin="16dp"
android:background="@drawable/overlay_background"
android:clickable="false"
android:gravity="center_horizontal"
android:orientation="vertical"
android:layout_margin="16dp"
android:visibility="gone"
android:background="@drawable/overlay_background">
tools:visibility="visible">
<TextView
android:id="@+id/gesture_volume_text"
@ -31,7 +33,7 @@
android:layout_height="24dp"
android:layout_marginVertical="16dp"
android:gravity="center"
android:textColor="@color/white"/>
android:textColor="@color/white" />
<ProgressBar
android:id="@+id/gesture_volume_progress_bar"
@ -39,7 +41,7 @@
android:layout_width="8dp"
android:layout_height="125dp"
android:progressDrawable="@drawable/progress_scale_drawable"
android:progress="58"/>
tools:progress="58" />
<ImageView
android:id="@+id/gesture_volume_image"
@ -55,12 +57,13 @@
android:layout_width="64dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|end"
android:layout_margin="16dp"
android:background="@drawable/overlay_background"
android:clickable="false"
android:gravity="center_horizontal"
android:orientation="vertical"
android:layout_margin="16dp"
android:visibility="gone"
android:background="@drawable/overlay_background">
tools:visibility="visible">
<TextView
android:id="@+id/gesture_brightness_text"
@ -68,7 +71,7 @@
android:layout_height="24dp"
android:layout_marginVertical="16dp"
android:gravity="center"
android:textColor="@color/white"/>
android:textColor="@color/white" />
<ProgressBar
android:id="@+id/gesture_brightness_progress_bar"
@ -76,7 +79,7 @@
android:layout_width="8dp"
android:layout_height="125dp"
android:progressDrawable="@drawable/progress_scale_drawable"
android:progress="58"/>
tools:progress="58" />
<ImageView
android:id="@+id/gesture_brightness_image"

View file

@ -1,63 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<merge xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:keep="@layout/exo_styled_player_view">
<com.google.android.exoplayer2.ui.AspectRatioFrameLayout android:id="@id/exo_content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center">
<!-- Video surface will be inserted as the first child of the content frame. -->
<View android:id="@id/exo_shutter"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/black"/>
<ImageView android:id="@id/exo_artwork"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="fitXY"/>
<ProgressBar android:id="@id/exo_buffering"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:indeterminate="true"
android:layout_gravity="center"/>
<TextView android:id="@id/exo_error_message"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginBottom="@dimen/exo_error_message_margin_bottom"
android:gravity="center"
android:textColor="@color/exo_white"
android:textSize="@dimen/exo_error_message_text_size"
android:lineSpacingMultiplier="1.1"
android:background="@drawable/exo_rounded_rectangle"
android:paddingLeft="@dimen/exo_error_message_text_padding_horizontal"
android:paddingRight="@dimen/exo_error_message_text_padding_horizontal"
android:paddingTop="@dimen/exo_error_message_text_padding_vertical"
android:paddingBottom="@dimen/exo_error_message_text_padding_vertical"/>
</com.google.android.exoplayer2.ui.AspectRatioFrameLayout>
<com.google.android.exoplayer2.ui.SubtitleView android:id="@id/exo_subtitles"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<FrameLayout android:id="@id/exo_ad_overlay"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<FrameLayout android:id="@id/exo_overlay"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<View android:id="@id/exo_controller_placeholder"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</merge>

View file

@ -62,6 +62,7 @@
android:layout_height="wrap_content"
android:layout_gravity="end"
android:background="@drawable/transparent_circle_background"
android:contentDescription="@string/select_playback_speed"
android:padding="16dp"
android:src="@drawable/ic_gauge"
app:tint="@color/white" />
@ -126,7 +127,7 @@
android:src="@drawable/ic_rewind" />
<ImageButton
android:id="@+id/exo_play"
android:id="@+id/exo_play_pause"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/circle_background"
@ -177,7 +178,8 @@
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="horizontal"
android:paddingStart="8dp">
android:paddingStart="8dp"
android:paddingEnd="8dp">
<TextView
android:id="@+id/exo_position"

View file

@ -0,0 +1,71 @@
<?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<com.google.android.exoplayer2.ui.AspectRatioFrameLayout
android:id="@id/exo_content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center">
<!-- Video surface will be inserted as the first child of the content frame. -->
<View
android:id="@id/exo_shutter"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/black" />
<ImageView
android:id="@id/exo_artwork"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="fitXY"
tools:ignore="ContentDescription" />
<ProgressBar
android:id="@id/exo_buffering"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:indeterminate="true" />
<TextView
android:id="@id/exo_error_message"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginBottom="64dp"
android:background="@drawable/overlay_background"
android:gravity="center"
android:lineSpacingMultiplier="1.1"
android:paddingLeft="12dp"
android:paddingTop="4dp"
android:paddingRight="12dp"
android:paddingBottom="4dp"
android:textColor="@color/white"
android:textSize="14sp" />
</com.google.android.exoplayer2.ui.AspectRatioFrameLayout>
<com.google.android.exoplayer2.ui.SubtitleView
android:id="@id/exo_subtitles"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<FrameLayout
android:id="@id/exo_ad_overlay"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<FrameLayout
android:id="@id/exo_overlay"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<View
android:id="@id/exo_controller_placeholder"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</merge>

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<drawable name="exo_styled_controls_play">@drawable/ic_play</drawable>
<drawable name="exo_styled_controls_pause">@drawable/ic_pause</drawable>
<resources xmlns:tools="http://schemas.android.com/tools">
<drawable name="exo_styled_controls_play" tools:ignore="PrivateResource">@drawable/ic_play</drawable>
<drawable name="exo_styled_controls_pause" tools:ignore="PrivateResource">@drawable/ic_pause</drawable>
</resources>