diff --git a/android/build.gradle b/android/build.gradle index 40d3f6b57..a8e5e1b5b 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -2,7 +2,7 @@ group 'com.jhomlala.better_player.better_player' version '1.0-SNAPSHOT' buildscript { - ext.exoPlayerVersion = "2.17.1" + ext.exoPlayerVersion = "2.18.0" ext.lifecycleVersion = "2.4.0-beta01" ext.annotationVersion = "1.2.0" ext.workVersion = "2.7.0" diff --git a/android/src/main/kotlin/com/jhomlala/better_player/BetterPlayer.kt b/android/src/main/kotlin/com/jhomlala/better_player/BetterPlayer.kt index f5e494430..0e22b1e23 100644 --- a/android/src/main/kotlin/com/jhomlala/better_player/BetterPlayer.kt +++ b/android/src/main/kotlin/com/jhomlala/better_player/BetterPlayer.kt @@ -4,7 +4,6 @@ import android.annotation.SuppressLint import android.app.NotificationChannel import android.app.NotificationManager import android.app.PendingIntent -import android.content.ComponentName import android.content.Context import android.content.Intent import android.graphics.Bitmap @@ -32,7 +31,6 @@ import com.google.android.exoplayer2.drm.FrameworkMediaDrm import com.google.android.exoplayer2.drm.UnsupportedDrmException import com.google.android.exoplayer2.drm.DummyExoMediaDrm import com.google.android.exoplayer2.drm.LocalMediaDrmCallback -import com.google.android.exoplayer2.upstream.DefaultDataSourceFactory import com.google.android.exoplayer2.source.MediaSource import com.google.android.exoplayer2.source.ClippingMediaSource import com.google.android.exoplayer2.ui.PlayerNotificationManager.MediaDescriptionAdapter @@ -51,14 +49,12 @@ import com.google.android.exoplayer2.source.hls.HlsMediaSource import com.google.android.exoplayer2.source.ProgressiveMediaSource import com.google.android.exoplayer2.extractor.DefaultExtractorsFactory import io.flutter.plugin.common.EventChannel.EventSink -import androidx.media.session.MediaButtonReceiver import androidx.work.Data import com.google.android.exoplayer2.* import com.google.android.exoplayer2.audio.AudioAttributes import com.google.android.exoplayer2.drm.DrmSessionManagerProvider import com.google.android.exoplayer2.ext.mediasession.MediaSessionConnector -import com.google.android.exoplayer2.trackselection.DefaultTrackSelector.SelectionOverride -import com.google.android.exoplayer2.trackselection.TrackSelectionOverrides +import com.google.android.exoplayer2.trackselection.TrackSelectionOverride import com.google.android.exoplayer2.upstream.DataSource import com.google.android.exoplayer2.upstream.DefaultDataSource import com.google.android.exoplayer2.util.Util @@ -383,17 +379,13 @@ internal class BetterPlayer( ): MediaSource { val type: Int if (formatHint == null) { - var lastPathSegment = uri.lastPathSegment - if (lastPathSegment == null) { - lastPathSegment = "" - } - type = Util.inferContentType(lastPathSegment) + type = Util.inferContentType(uri) } else { type = when (formatHint) { - FORMAT_SS -> C.TYPE_SS - FORMAT_DASH -> C.TYPE_DASH - FORMAT_HLS -> C.TYPE_HLS - FORMAT_OTHER -> C.TYPE_OTHER + FORMAT_SS -> C.CONTENT_TYPE_SS + FORMAT_DASH -> C.CONTENT_TYPE_DASH + FORMAT_HLS -> C.CONTENT_TYPE_HLS + FORMAT_OTHER -> C.CONTENT_TYPE_OTHER else -> -1 } } @@ -408,26 +400,42 @@ internal class BetterPlayer( drmSessionManagerProvider = DrmSessionManagerProvider { drmSessionManager } } return when (type) { - C.TYPE_SS -> SsMediaSource.Factory( + C.CONTENT_TYPE_SS -> SsMediaSource.Factory( DefaultSsChunkSource.Factory(mediaDataSourceFactory), DefaultDataSource.Factory(context, mediaDataSourceFactory) ) - .setDrmSessionManagerProvider(drmSessionManagerProvider) + .apply { + if (drmSessionManagerProvider != null) { + setDrmSessionManagerProvider(drmSessionManagerProvider!!) + } + } .createMediaSource(mediaItem) - C.TYPE_DASH -> DashMediaSource.Factory( + C.CONTENT_TYPE_DASH -> DashMediaSource.Factory( DefaultDashChunkSource.Factory(mediaDataSourceFactory), DefaultDataSource.Factory(context, mediaDataSourceFactory) ) - .setDrmSessionManagerProvider(drmSessionManagerProvider) + .apply { + if (drmSessionManagerProvider != null) { + setDrmSessionManagerProvider(drmSessionManagerProvider!!) + } + } .createMediaSource(mediaItem) - C.TYPE_HLS -> HlsMediaSource.Factory(mediaDataSourceFactory) - .setDrmSessionManagerProvider(drmSessionManagerProvider) + C.CONTENT_TYPE_HLS -> HlsMediaSource.Factory(mediaDataSourceFactory) + .apply { + if (drmSessionManagerProvider != null) { + setDrmSessionManagerProvider(drmSessionManagerProvider!!) + } + } .createMediaSource(mediaItem) - C.TYPE_OTHER -> ProgressiveMediaSource.Factory( + C.CONTENT_TYPE_OTHER -> ProgressiveMediaSource.Factory( mediaDataSourceFactory, DefaultExtractorsFactory() ) - .setDrmSessionManagerProvider(drmSessionManagerProvider) + .apply { + if (drmSessionManagerProvider != null) { + setDrmSessionManagerProvider(drmSessionManagerProvider!!) + } + } .createMediaSource(mediaItem) else -> { throw IllegalStateException("Unsupported type: $type") @@ -508,12 +516,12 @@ internal class BetterPlayer( val audioComponent = exoPlayer?.audioComponent ?: return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { audioComponent.setAudioAttributes( - AudioAttributes.Builder().setContentType(C.CONTENT_TYPE_MOVIE).build(), + AudioAttributes.Builder().setContentType(C.AUDIO_CONTENT_TYPE_MOVIE).build(), !mixWithOthers ) } else { audioComponent.setAudioAttributes( - AudioAttributes.Builder().setContentType(C.CONTENT_TYPE_MUSIC).build(), + AudioAttributes.Builder().setContentType(C.AUDIO_CONTENT_TYPE_MUSIC).build(), !mixWithOthers ) } @@ -707,17 +715,12 @@ internal class BetterPlayer( if (mappedTrackInfo != null) { val builder = trackSelector.parameters.buildUpon() .setRendererDisabled(rendererIndex, false) - .setTrackSelectionOverrides( - TrackSelectionOverrides.Builder().addOverride( - TrackSelectionOverrides.TrackSelectionOverride( - mappedTrackInfo.getTrackGroups( - rendererIndex - ).get(groupIndex) - ) - ).build() + .addOverride(TrackSelectionOverride(mappedTrackInfo.getTrackGroups(rendererIndex) + .get(groupIndex), rendererIndex) ) + .build() - trackSelector.setParameters(builder) + trackSelector.parameters = builder } }