Skip to content

Commit

Permalink
fix(player): add support for m3u8 files with weird txt extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
rhenwinch committed May 30, 2024
1 parent 77cf887 commit 5145d31
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@ import androidx.media3.common.Format
import androidx.media3.common.MediaItem
import androidx.media3.common.MediaItem.SubtitleConfiguration
import androidx.media3.common.MediaMetadata
import androidx.media3.common.MimeTypes
import androidx.media3.common.PlaybackException
import androidx.media3.common.Player
import androidx.media3.common.Tracks
import androidx.media3.common.util.UnstableApi
import androidx.media3.datasource.DefaultDataSource
import androidx.media3.datasource.DefaultHttpDataSource
import androidx.media3.datasource.HttpDataSource.InvalidResponseCodeException
import androidx.media3.datasource.okhttp.OkHttpDataSource
import androidx.media3.exoplayer.ExoPlayer
import androidx.media3.exoplayer.SeekParameters
Expand Down Expand Up @@ -164,6 +166,13 @@ class FlixclusivePlayerManager(
override fun onPlayerError(error: PlaybackException) {
errorLog(error.stackTraceToString())

if (error.cause is InvalidResponseCodeException) {
val okHttpError = error.cause as InvalidResponseCodeException
errorLog("Headers: ${okHttpError.dataSpec.httpRequestHeaders}")
errorLog("Url: ${okHttpError.dataSpec.uri}")
errorLog("Body: ${String(okHttpError.responseBody)}")
}

player?.run {
prepare()
playWhenReady = this@FlixclusivePlayerManager.playWhenReady
Expand Down Expand Up @@ -249,12 +258,11 @@ class FlixclusivePlayerManager(
player?.run {
debugLog("Preparing the player...")

val mediaSource = cacheFactory.createMediaSource(
createMediaItem(
url = link.url,
title = title
)
val mediaItem = createMediaItem(
url = link.url,
title = title
)
val mediaSource = cacheFactory.createMediaSource(mediaItem)

setMediaSource(
/* mediaSource = */ MergingMediaSource(mediaSource, *createSubtitleSources(subtitles)),
Expand Down Expand Up @@ -306,6 +314,11 @@ class FlixclusivePlayerManager(
.setDisplayTitle(title)
.build()
)
.apply {
if (url.endsWith(".txt")) {
setMimeType(MimeTypes.APPLICATION_M3U8)
}
}
.build()

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import org.json.JSONArray
import org.json.JSONObject


const val USER_AGENT = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36"
const val USER_AGENT = "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.3) Gecko/20090912 Gentoo Firefox/3.5.3 FirePHP/0.3"
/**
* Enum class representing HTTP request methods.
* @property requiresBody Indicates whether the HTTP method typically requires a request body or data.
Expand Down

0 comments on commit 5145d31

Please sign in to comment.