Skip to content

Commit

Permalink
Fix: Resolve default http data source factory error on exoplayer utils
Browse files Browse the repository at this point in the history
Error Message: "e: /Users/.../WordPress-Android/WordPress/src/main/java/
org/wordpress/android/ui/media/ExoPlayerUtils.kt: (19, 47):
Unresolved reference: DefaultHttpDataSourceFactory"

As part of the 'ExoPlayer' version '2.16.0' the deprecated
'DefaultHttpDataSourceFactory' got removed in favor of
'DefaultHttpDataSource.Factory'.

Release Notes: https://github.com/google/ExoPlayer/releases/tag/r2.16.0

PS: Also, the 'DashMediaSource.Factory' import got update to resolve
'Factory' related import conflicts.
  • Loading branch information
ParaskP7 committed Feb 9, 2023
1 parent f9a237f commit 93b85f1
Showing 1 changed file with 10 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ import com.google.android.exoplayer2.C.ContentType
import com.google.android.exoplayer2.offline.FilteringManifestParser
import com.google.android.exoplayer2.source.ProgressiveMediaSource
import com.google.android.exoplayer2.source.MediaSource
import com.google.android.exoplayer2.source.dash.DashMediaSource.Factory
import com.google.android.exoplayer2.source.dash.DashMediaSource
import com.google.android.exoplayer2.source.dash.manifest.DashManifestParser
import com.google.android.exoplayer2.source.hls.HlsMediaSource
import com.google.android.exoplayer2.source.hls.playlist.DefaultHlsPlaylistParserFactory
import com.google.android.exoplayer2.source.smoothstreaming.SsMediaSource
import com.google.android.exoplayer2.source.smoothstreaming.manifest.SsManifestParser
import com.google.android.exoplayer2.upstream.DefaultDataSourceFactory
import com.google.android.exoplayer2.upstream.DefaultHttpDataSourceFactory
import com.google.android.exoplayer2.upstream.DefaultHttpDataSource
import com.google.android.exoplayer2.util.Util
import dagger.Reusable
import org.wordpress.android.WordPress
Expand All @@ -29,25 +29,26 @@ class ExoPlayerUtils @Inject constructor(
private val authenticationUtils: AuthenticationUtils,
private val appContext: Context
) {
private var httpDataSourceFactory: DefaultHttpDataSourceFactory? = null
private var httpDataSourceFactory: DefaultHttpDataSource.Factory? = null

fun buildHttpDataSourceFactory(url: String): DefaultHttpDataSourceFactory {
fun buildHttpDataSourceFactory(url: String): DefaultHttpDataSource.Factory {
if (httpDataSourceFactory == null) {
httpDataSourceFactory = DefaultHttpDataSourceFactory(WordPress.getUserAgent())
httpDataSourceFactory = DefaultHttpDataSource.Factory()
.setUserAgent(WordPress.getUserAgent())
}
httpDataSourceFactory?.defaultRequestProperties?.set(authenticationUtils.getAuthHeaders(url))
return httpDataSourceFactory as DefaultHttpDataSourceFactory
httpDataSourceFactory?.setDefaultRequestProperties(authenticationUtils.getAuthHeaders(url))
return httpDataSourceFactory as DefaultHttpDataSource.Factory
}

private fun buildDefaultDataSourceFactory(httpDataSourceFactory: DefaultHttpDataSourceFactory) =
private fun buildDefaultDataSourceFactory(httpDataSourceFactory: DefaultHttpDataSource.Factory) =
DefaultDataSourceFactory(appContext, httpDataSourceFactory)

@Suppress("UseCheckOrError")
fun buildMediaSource(uri: Uri): MediaSource? {
val httpDataSourceFactory = buildHttpDataSourceFactory(uri.toString())
val defaultDataSourceFactory = buildDefaultDataSourceFactory(httpDataSourceFactory)
return when (@ContentType val type = Util.inferContentType(uri)) {
C.TYPE_DASH -> Factory(defaultDataSourceFactory)
C.TYPE_DASH -> DashMediaSource.Factory(defaultDataSourceFactory)
.setManifestParser(FilteringManifestParser(DashManifestParser(), null))
.createMediaSource(uri)
C.TYPE_SS -> SsMediaSource.Factory(defaultDataSourceFactory)
Expand Down

0 comments on commit 93b85f1

Please sign in to comment.