Skip to content

Commit

Permalink
Migrate to androidx.media3
Browse files Browse the repository at this point in the history
  • Loading branch information
nielsvanvelzen committed Jun 26, 2023
1 parent ed2b7f7 commit 52ce520
Show file tree
Hide file tree
Showing 21 changed files with 94 additions and 92 deletions.
4 changes: 4 additions & 0 deletions android-lint.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,8 @@
<!-- Weblate doesn't use ellipsis characters -->
<ignore regexp="app/src/main/res/values-.*" />
</issue>
<issue id="UnsafeOptInUsageError">
<!-- We use a lot of "unstable" media3 apis -->
<ignore regexp="\(markerClass = androidx\.media3\.common\.util\.UnstableApi\.class\)" />
</issue>
</lint>
4 changes: 2 additions & 2 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -152,12 +152,12 @@ dependencies {
// Media
implementation(libs.androidx.media)
implementation(libs.androidx.mediarouter)
implementation(libs.bundles.exoplayer) {
implementation(libs.bundles.androidx.media3) {
// Exclude Play Services cronet provider library
exclude("com.google.android.gms", "play-services-cronet")
}
implementation(libs.jellyfin.exoplayer.ffmpegextension)
proprietaryImplementation(libs.exoplayer.cast)
proprietaryImplementation(libs.androidx.media3.cast)
proprietaryImplementation(libs.bundles.playservices)

// Room
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.jellyfin.mobile.player.cast

import com.google.android.exoplayer2.Player
import androidx.media3.common.Player
import org.jellyfin.mobile.player.audio.MediaService

class CastPlayerProvider(@Suppress("UNUSED_PARAMETER") mediaService: MediaService) : ICastPlayerProvider {
Expand Down
24 changes: 12 additions & 12 deletions app/src/main/java/org/jellyfin/mobile/app/AppModule.kt
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
package org.jellyfin.mobile.app

import android.content.Context
import androidx.media3.common.util.Util
import androidx.media3.datasource.DataSource
import androidx.media3.datasource.DefaultDataSource
import androidx.media3.datasource.DefaultHttpDataSource
import androidx.media3.datasource.cronet.CronetDataSource
import androidx.media3.exoplayer.hls.HlsMediaSource
import androidx.media3.exoplayer.source.DefaultMediaSourceFactory
import androidx.media3.exoplayer.source.MediaSource
import androidx.media3.exoplayer.source.ProgressiveMediaSource
import androidx.media3.exoplayer.source.SingleSampleMediaSource
import androidx.media3.extractor.DefaultExtractorsFactory
import androidx.media3.extractor.ts.TsExtractor
import coil.ImageLoader
import com.google.android.exoplayer2.ext.cronet.CronetDataSource
import com.google.android.exoplayer2.extractor.DefaultExtractorsFactory
import com.google.android.exoplayer2.extractor.ts.TsExtractor
import com.google.android.exoplayer2.source.DefaultMediaSourceFactory
import com.google.android.exoplayer2.source.MediaSource
import com.google.android.exoplayer2.source.ProgressiveMediaSource
import com.google.android.exoplayer2.source.SingleSampleMediaSource
import com.google.android.exoplayer2.source.hls.HlsMediaSource
import com.google.android.exoplayer2.upstream.DataSource
import com.google.android.exoplayer2.upstream.DefaultDataSource
import com.google.android.exoplayer2.upstream.DefaultHttpDataSource
import com.google.android.exoplayer2.util.Util
import kotlinx.coroutines.channels.Channel
import okhttp3.OkHttpClient
import org.chromium.net.CronetEngine
Expand Down
28 changes: 14 additions & 14 deletions app/src/main/java/org/jellyfin/mobile/player/PlayerViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,20 @@ import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ProcessLifecycleOwner
import androidx.lifecycle.viewModelScope
import com.google.android.exoplayer2.C
import com.google.android.exoplayer2.DefaultRenderersFactory
import com.google.android.exoplayer2.ExoPlayer
import com.google.android.exoplayer2.PlaybackException
import com.google.android.exoplayer2.Player
import com.google.android.exoplayer2.analytics.DefaultAnalyticsCollector
import com.google.android.exoplayer2.mediacodec.MediaCodecDecoderException
import com.google.android.exoplayer2.mediacodec.MediaCodecInfo
import com.google.android.exoplayer2.mediacodec.MediaCodecSelector
import com.google.android.exoplayer2.source.MediaSource
import com.google.android.exoplayer2.trackselection.DefaultTrackSelector
import com.google.android.exoplayer2.util.Clock
import com.google.android.exoplayer2.util.EventLogger
import com.google.android.exoplayer2.util.MimeTypes
import androidx.media3.common.C
import androidx.media3.common.MimeTypes
import androidx.media3.common.PlaybackException
import androidx.media3.common.Player
import androidx.media3.common.util.Clock
import androidx.media3.exoplayer.DefaultRenderersFactory
import androidx.media3.exoplayer.ExoPlayer
import androidx.media3.exoplayer.analytics.DefaultAnalyticsCollector
import androidx.media3.exoplayer.mediacodec.MediaCodecDecoderException
import androidx.media3.exoplayer.mediacodec.MediaCodecInfo
import androidx.media3.exoplayer.mediacodec.MediaCodecSelector
import androidx.media3.exoplayer.source.MediaSource
import androidx.media3.exoplayer.trackselection.DefaultTrackSelector
import androidx.media3.exoplayer.util.EventLogger
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.jellyfin.mobile.player

import com.google.android.exoplayer2.C
import com.google.android.exoplayer2.trackselection.DefaultTrackSelector
import androidx.media3.common.C
import androidx.media3.exoplayer.trackselection.DefaultTrackSelector
import org.jellyfin.mobile.player.source.ExternalSubtitleStream
import org.jellyfin.mobile.player.source.JellyfinMediaSource
import org.jellyfin.mobile.utils.clearSelectionAndDisableRendererByType
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ import android.net.Uri
import android.support.v4.media.session.MediaControllerCompat
import android.support.v4.media.session.MediaSessionCompat
import androidx.core.graphics.drawable.toBitmap
import androidx.media3.common.ForwardingPlayer
import androidx.media3.common.Player
import androidx.media3.ui.PlayerNotificationManager
import coil.ImageLoader
import coil.request.ImageRequest
import com.google.android.exoplayer2.ForwardingPlayer
import com.google.android.exoplayer2.Player
import com.google.android.exoplayer2.ui.PlayerNotificationManager
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.SupervisorJob
Expand Down
20 changes: 9 additions & 11 deletions app/src/main/java/org/jellyfin/mobile/player/audio/MediaService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,17 @@ import android.support.v4.media.session.PlaybackStateCompat
import android.widget.Toast
import androidx.core.content.ContextCompat
import androidx.media.MediaBrowserServiceCompat
import androidx.media3.common.AudioAttributes
import androidx.media3.common.C
import androidx.media3.common.PlaybackException
import androidx.media3.common.Player
import androidx.media3.exoplayer.ExoPlayer
import androidx.media3.exoplayer.source.MediaSource
import androidx.media3.ui.PlayerNotificationManager
import androidx.mediarouter.media.MediaControlIntent
import androidx.mediarouter.media.MediaRouteSelector
import androidx.mediarouter.media.MediaRouter
import androidx.mediarouter.media.MediaRouterParams
import com.google.android.exoplayer2.C
import com.google.android.exoplayer2.ExoPlayer
import com.google.android.exoplayer2.PlaybackException
import com.google.android.exoplayer2.Player
import com.google.android.exoplayer2.audio.AudioAttributes
import com.google.android.exoplayer2.ext.mediasession.MediaSessionConnector
import com.google.android.exoplayer2.ext.mediasession.TimelineQueueNavigator
import com.google.android.exoplayer2.source.MediaSource
import com.google.android.exoplayer2.ui.PlayerNotificationManager
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
import kotlinx.coroutines.MainScope
Expand All @@ -49,7 +47,7 @@ import org.jellyfin.sdk.api.client.exception.ApiClientException
import org.koin.android.ext.android.get
import org.koin.android.ext.android.inject
import timber.log.Timber
import com.google.android.exoplayer2.MediaItem as ExoPlayerMediaItem
import androidx.media3.common.MediaItem as Media3Item

class MediaService : MediaBrowserServiceCompat() {
private val apiClientController: ApiClientController by inject()
Expand Down Expand Up @@ -203,7 +201,7 @@ class MediaService : MediaBrowserServiceCompat() {
currentPlaylistItems = metadataList

val mediaItems = metadataList.map { metadata ->
ExoPlayerMediaItem.Builder().apply {
Media3Item.Builder().apply {
setUri(metadata.mediaUri)
setTag(metadata)
}.build()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.jellyfin.mobile.player.cast

import com.google.android.exoplayer2.Player
import androidx.media3.common.Player

interface ICastPlayerProvider {
val isCastSessionAvailable: Boolean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package org.jellyfin.mobile.player.deviceprofile

import android.media.MediaCodecInfo.CodecProfileLevel
import android.media.MediaFormat
import com.google.android.exoplayer2.util.MimeTypes
import androidx.media3.common.MimeTypes

@Suppress("TooManyFunctions", "CyclomaticComplexMethod")
object CodecHelpers {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ import android.graphics.Bitmap
import androidx.core.content.getSystemService
import androidx.core.graphics.drawable.toBitmap
import androidx.lifecycle.viewModelScope
import androidx.media3.common.Player
import coil.ImageLoader
import coil.request.ImageRequest
import com.google.android.exoplayer2.Player
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import android.net.Uri
import androidx.annotation.CheckResult
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import com.google.android.exoplayer2.MediaItem
import com.google.android.exoplayer2.source.MediaSource
import com.google.android.exoplayer2.source.MergingMediaSource
import com.google.android.exoplayer2.source.ProgressiveMediaSource
import com.google.android.exoplayer2.source.SingleSampleMediaSource
import com.google.android.exoplayer2.source.hls.HlsMediaSource
import androidx.media3.common.MediaItem
import androidx.media3.exoplayer.hls.HlsMediaSource
import androidx.media3.exoplayer.source.MediaSource
import androidx.media3.exoplayer.source.MergingMediaSource
import androidx.media3.exoplayer.source.ProgressiveMediaSource
import androidx.media3.exoplayer.source.SingleSampleMediaSource
import org.jellyfin.mobile.player.PlayerException
import org.jellyfin.mobile.player.PlayerViewModel
import org.jellyfin.mobile.player.deviceprofile.DeviceProfileBuilder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ import androidx.core.view.updatePadding
import androidx.fragment.app.Fragment
import androidx.fragment.app.viewModels
import androidx.lifecycle.lifecycleScope
import com.google.android.exoplayer2.Player
import com.google.android.exoplayer2.ui.PlayerView
import androidx.media3.common.Player
import androidx.media3.ui.PlayerView
import kotlinx.coroutines.Job
import kotlinx.coroutines.launch
import org.jellyfin.mobile.R
Expand All @@ -49,7 +49,7 @@ import org.jellyfin.mobile.utils.extensions.keepScreenOn
import org.jellyfin.mobile.utils.toast
import org.jellyfin.sdk.model.api.MediaStream
import org.koin.android.ext.android.inject
import com.google.android.exoplayer2.ui.R as ExoplayerR
import androidx.media3.ui.R as Media3R

class PlayerFragment : Fragment() {
private val appPreferences: AppPreferences by inject()
Expand Down Expand Up @@ -330,7 +330,7 @@ class PlayerFragment : Fragment() {
}
}
setAspectRatio(aspectRational)
val contentFrame: View = playerView.findViewById(ExoplayerR.id.exo_content_frame)
val contentFrame: View = playerView.findViewById(Media3R.id.exo_content_frame)
val contentRect = with(contentFrame) {
val (x, y) = intArrayOf(0, 0).also(::getLocationInWindow)
Rect(x, y, x + width, y + height)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import android.widget.ProgressBar
import androidx.core.content.getSystemService
import androidx.core.view.isVisible
import androidx.core.view.postDelayed
import com.google.android.exoplayer2.ui.AspectRatioFrameLayout
import com.google.android.exoplayer2.ui.PlayerView
import androidx.media3.ui.AspectRatioFrameLayout
import androidx.media3.ui.PlayerView
import org.jellyfin.mobile.R
import org.jellyfin.mobile.app.AppPreferences
import org.jellyfin.mobile.databinding.FragmentPlayerBinding
Expand Down Expand Up @@ -122,7 +122,7 @@ class PlayerGestureHelper(

override fun onSingleTapConfirmed(e: MotionEvent): Boolean {
playerView.apply {
if (!isControllerVisible) showController() else hideController()
if (!isControllerFullyVisible) showController() else hideController()
}
return true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import android.content.pm.ActivityInfo
import android.view.OrientationEventListener
import android.widget.ImageButton
import androidx.core.view.isVisible
import com.google.android.exoplayer2.ui.PlayerView
import androidx.media3.ui.PlayerView
import org.jellyfin.mobile.databinding.FragmentPlayerBinding
import org.jellyfin.mobile.utils.AndroidVersion
import org.jellyfin.mobile.utils.Constants
Expand Down Expand Up @@ -50,7 +50,7 @@ class PlayerLockScreenHelper(
if (!AndroidVersion.isAtLeastN || !activity.isInPictureInPictureMode) {
playerView.useController = true
playerView.apply {
if (!isControllerVisible) showController()
if (!isControllerFullyVisible) showController()
}
}
}
Expand Down
14 changes: 7 additions & 7 deletions app/src/main/java/org/jellyfin/mobile/utils/MediaExtensions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ import android.media.AudioManager
import android.media.MediaMetadata
import android.media.session.MediaSession
import android.media.session.PlaybackState
import com.google.android.exoplayer2.C
import com.google.android.exoplayer2.ExoPlayer
import com.google.android.exoplayer2.Player
import com.google.android.exoplayer2.analytics.AnalyticsCollector
import androidx.media3.common.C
import androidx.media3.common.Player
import androidx.media3.exoplayer.ExoPlayer
import androidx.media3.exoplayer.analytics.AnalyticsCollector
import org.jellyfin.mobile.player.source.JellyfinMediaSource
import org.jellyfin.mobile.utils.extensions.width
import com.google.android.exoplayer2.audio.AudioAttributes as ExoPlayerAudioAttributes
import androidx.media3.common.AudioAttributes as Media3AudioAttributes

inline fun MediaSession.applyDefaultLocalAudioAttributes(contentType: Int) {
val audioAttributes = AudioAttributes.Builder().apply {
Expand Down Expand Up @@ -72,10 +72,10 @@ fun AudioManager.getVolumeLevelPercent(): Int {
}

/**
* Set ExoPlayer [ExoPlayerAudioAttributes], make ExoPlayer handle audio focus
* Set ExoPlayer [Media3AudioAttributes], make ExoPlayer handle audio focus
*/
inline fun ExoPlayer.applyDefaultAudioAttributes(@C.AudioContentType contentType: Int) {
val audioAttributes = ExoPlayerAudioAttributes.Builder()
val audioAttributes = Media3AudioAttributes.Builder()
.setUsage(C.USAGE_MEDIA)
.setContentType(contentType)
.build()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package org.jellyfin.mobile.utils

import com.google.android.exoplayer2.C
import com.google.android.exoplayer2.source.TrackGroup
import com.google.android.exoplayer2.trackselection.DefaultTrackSelector
import com.google.android.exoplayer2.trackselection.TrackSelectionOverride
import androidx.media3.common.TrackGroup
import androidx.media3.common.TrackSelectionOverride
import androidx.media3.exoplayer.trackselection.DefaultTrackSelector

/**
* Select the [trackGroup] of the specified [type] and ensure the type is enabled.
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/exo_player_control_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
app:layout_constraintTop_toTopOf="@id/exo_progress"
tools:text="33:01" />

<com.google.android.exoplayer2.ui.DefaultTimeBar
<androidx.media3.ui.DefaultTimeBar
android:id="@+id/exo_progress"
android:layout_width="0dp"
android:layout_height="wrap_content"
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/fragment_player.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
android:layout_height="match_parent"
android:background="@android:color/black">

<com.google.android.exoplayer2.ui.PlayerView
<androidx.media3.ui.PlayerView
android:id="@+id/player_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package org.jellyfin.mobile.player.cast

import com.google.android.exoplayer2.Player
import com.google.android.exoplayer2.ext.cast.CastPlayer
import com.google.android.exoplayer2.ext.cast.SessionAvailabilityListener
import androidx.media3.cast.CastPlayer
import androidx.media3.cast.SessionAvailabilityListener
import androidx.media3.common.Player
import com.google.android.gms.cast.framework.CastContext
import org.jellyfin.mobile.player.audio.MediaService

Expand Down
Loading

0 comments on commit 52ce520

Please sign in to comment.