Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed BUG java.lang.NullPointerException: MediaSource.Factory#setDrmSessionManagerProvider #1324

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,5 @@ This plugin is based on [Chewie](https://github.com/brianegan/chewie). Chewie is
This plugin development is in progress. You may encounter breaking changes each version. This plugin is developed part-time for free. If you need
some feature which is supported by other players available in pub dev, then feel free to create PR. All valuable contributions are welcome!


## Current fork fix
The ExoPlayer version has been updated to version 2.19.1. Fixed incompatibility with just_audio and video_player libraries on Android.
18 changes: 9 additions & 9 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@ group 'com.jhomlala.better_player.better_player'
version '1.0-SNAPSHOT'

buildscript {
ext.exoPlayerVersion = "2.17.1"
ext.lifecycleVersion = "2.4.0-beta01"
ext.annotationVersion = "1.2.0"
ext.workVersion = "2.7.0"
ext.exoPlayerVersion = "2.19.1"
ext.lifecycleVersion = "2.6.0-alpha02"
ext.annotationVersion = "1.4.0"
ext.workVersion = "2.7.1"
ext.coreVersion = "1.6.0"
ext.gradleVersion = "7.0.2"
ext.kotlinVersion = "1.5.31"
ext.gradleVersion = "7.3.0"
ext.kotlinVersion = "1.9.0"

repositories {
google()
mavenCentral()
}

dependencies {
classpath 'com.android.tools.build:gradle:4.1.0'
classpath 'com.android.tools.build:gradle:4.1.3'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
}
}
Expand All @@ -32,7 +32,7 @@ apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'

android {
compileSdkVersion 31
compileSdkVersion 33

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
Expand All @@ -48,7 +48,7 @@ android {
}

defaultConfig {
minSdkVersion 16
minSdkVersion 21
}

dependencies {
Expand Down
2 changes: 1 addition & 1 deletion android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
79 changes: 42 additions & 37 deletions android/src/main/kotlin/com/jhomlala/better_player/BetterPlayer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -42,6 +40,7 @@ import android.support.v4.media.session.PlaybackStateCompat
import android.support.v4.media.MediaMetadataCompat
import android.util.Log
import android.view.Surface
import androidx.annotation.RequiresApi
import androidx.lifecycle.Observer
import com.google.android.exoplayer2.source.smoothstreaming.SsMediaSource
import com.google.android.exoplayer2.source.smoothstreaming.DefaultSsChunkSource
Expand All @@ -51,14 +50,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
Expand Down Expand Up @@ -214,6 +211,7 @@ internal class BetterPlayer(
return title
}

@RequiresApi(Build.VERSION_CODES.M)
@SuppressLint("UnspecifiedImmutableFlag")
override fun createCurrentContentIntent(player: Player): PendingIntent? {
val packageName = context.applicationContext.packageName
Expand Down Expand Up @@ -387,13 +385,13 @@ internal class BetterPlayer(
if (lastPathSegment == null) {
lastPathSegment = ""
}
type = Util.inferContentType(lastPathSegment)
type = Util.inferContentTypeForExtension(lastPathSegment)
} 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
}
}
Expand All @@ -408,27 +406,36 @@ 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)
.createMediaSource(mediaItem)
C.TYPE_DASH -> DashMediaSource.Factory(
).apply {
if (drmSessionManagerProvider != null) {
setDrmSessionManagerProvider(drmSessionManagerProvider!!)
}
}.createMediaSource(mediaItem)
C.CONTENT_TYPE_DASH -> DashMediaSource.Factory(
DefaultDashChunkSource.Factory(mediaDataSourceFactory),
DefaultDataSource.Factory(context, mediaDataSourceFactory)
)
.setDrmSessionManagerProvider(drmSessionManagerProvider)
.createMediaSource(mediaItem)
C.TYPE_HLS -> HlsMediaSource.Factory(mediaDataSourceFactory)
.setDrmSessionManagerProvider(drmSessionManagerProvider)
.createMediaSource(mediaItem)
C.TYPE_OTHER -> ProgressiveMediaSource.Factory(
).apply {
if (drmSessionManagerProvider != null) {
setDrmSessionManagerProvider(drmSessionManagerProvider!!)
}
}.createMediaSource(mediaItem)
C.CONTENT_TYPE_HLS -> HlsMediaSource.Factory(mediaDataSourceFactory)
.apply {
if (drmSessionManagerProvider != null) {
setDrmSessionManagerProvider(drmSessionManagerProvider!!)
}
}.createMediaSource(mediaItem)
C.CONTENT_TYPE_OTHER -> ProgressiveMediaSource.Factory(
mediaDataSourceFactory,
DefaultExtractorsFactory()
)
.setDrmSessionManagerProvider(drmSessionManagerProvider)
.createMediaSource(mediaItem)
).apply {
if (drmSessionManagerProvider != null) {
setDrmSessionManagerProvider(drmSessionManagerProvider!!)
}
}.createMediaSource(mediaItem)
else -> {
throw IllegalStateException("Unsupported type: $type")
}
Expand Down Expand Up @@ -508,12 +515,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
)
}
Expand Down Expand Up @@ -707,14 +714,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),
mappedTrackInfo.getTrackGroups(rendererIndex)
.indexOf(mappedTrackInfo.getTrackGroups(rendererIndex).get(groupIndex))
)
)

trackSelector.setParameters(builder)
Expand Down Expand Up @@ -771,8 +776,8 @@ internal class BetterPlayer(
//Clear cache without accessing BetterPlayerCache.
fun clearCache(context: Context?, result: MethodChannel.Result) {
try {
context?.let { context ->
val file = File(context.cacheDir, "betterPlayerCache")
context?.let {
val file = File(it.cacheDir, "betterPlayerCache")
deleteDirectory(file)
}
result.success(null)
Expand Down
2 changes: 1 addition & 1 deletion example/android/settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pluginManagement {
plugins {
id "dev.flutter.flutter-plugin-loader" version "1.0.0"
id "com.android.application" version "7.3.0" apply false
id "org.jetbrains.kotlin.android" version "1.7.10" apply false
id "org.jetbrains.kotlin.android" version "1.9.0" apply false
}

include ":app"
Loading