Revert "Bumped the exoplayer version and fixed the audio & video track selection"

This reverts commit 93cbd29f3d.
This commit is contained in:
Blatzar 2022-10-27 18:31:38 +02:00
parent 93cbd29f3d
commit 6b586388b9
8 changed files with 43 additions and 108 deletions

View file

@ -155,10 +155,10 @@ dependencies {
// implementation("androidx.leanback:leanback-paging:1.1.0-alpha09") // implementation("androidx.leanback:leanback-paging:1.1.0-alpha09")
// Exoplayer // Exoplayer
implementation("com.google.android.exoplayer:exoplayer:2.18.1") implementation("com.google.android.exoplayer:exoplayer:2.16.1")
implementation("com.google.android.exoplayer:extension-cast:2.18.1") implementation("com.google.android.exoplayer:extension-cast:2.16.1")
implementation("com.google.android.exoplayer:extension-mediasession:2.18.1") implementation("com.google.android.exoplayer:extension-mediasession:2.16.1")
implementation("com.google.android.exoplayer:extension-okhttp:2.18.1") implementation("com.google.android.exoplayer:extension-okhttp:2.16.1")
//implementation("com.google.android.exoplayer:extension-leanback:2.14.0") //implementation("com.google.android.exoplayer:extension-leanback:2.14.0")

View file

@ -150,7 +150,7 @@ class SelectSourceController(val view: ImageView, val activity: ControllerActivi
} else { } else {
ChromecastSubtitlesFragment.getCurrentSavedStyle().apply { ChromecastSubtitlesFragment.getCurrentSavedStyle().apply {
val font = TextTrackStyle() val font = TextTrackStyle()
font.setFontFamily(fontFamily ?: "Google Sans") font.fontFamily = fontFamily ?: "Google Sans"
fontGenericFamily?.let { fontGenericFamily?.let {
font.fontGenericFamily = it font.fontGenericFamily = it
} }
@ -183,9 +183,7 @@ class SelectSourceController(val view: ImageView, val activity: ControllerActivi
val contentUrl = (remoteMediaClient?.currentItem?.media?.contentUrl val contentUrl = (remoteMediaClient?.currentItem?.media?.contentUrl
?: remoteMediaClient?.currentItem?.media?.contentId) ?: remoteMediaClient?.currentItem?.media?.contentId)
val sortingMethods = val sortingMethods = items.map { "${it.name} ${Qualities.getStringByInt(it.quality)}" }.toTypedArray()
items.map { "${it.name} ${Qualities.getStringByInt(it.quality)}" }
.toTypedArray()
val sotringIndex = items.indexOfFirst { it.url == contentUrl } val sotringIndex = items.indexOfFirst { it.url == contentUrl }
val arrayAdapter = val arrayAdapter =
@ -281,7 +279,7 @@ class SelectSourceController(val view: ImageView, val activity: ControllerActivi
val currentPosition = remoteMediaClient?.approximateStreamPosition val currentPosition = remoteMediaClient?.approximateStreamPosition
if (currentDuration != null && currentPosition != null) if (currentDuration != null && currentPosition != null)
DataStoreHelper.setViewPos(epData.id, currentPosition, currentDuration) DataStoreHelper.setViewPos(epData.id, currentPosition, currentDuration)
} catch (t: Throwable) { } catch (t : Throwable) {
logError(t) logError(t)
} }
@ -360,8 +358,10 @@ class SelectSourceController(val view: ImageView, val activity: ControllerActivi
} }
} }
override fun onSessionConnected(castSession: CastSession) { override fun onSessionConnected(castSession: CastSession?) {
super.onSessionConnected(castSession) castSession?.let {
super.onSessionConnected(it)
}
remoteMediaClient?.queueSetRepeatMode(REPEAT_MODE_REPEAT_OFF, JSONObject()) remoteMediaClient?.queueSetRepeatMode(REPEAT_MODE_REPEAT_OFF, JSONObject())
} }
} }

View file

@ -15,7 +15,6 @@ import com.google.android.exoplayer2.ext.okhttp.OkHttpDataSource
import com.google.android.exoplayer2.source.* import com.google.android.exoplayer2.source.*
import com.google.android.exoplayer2.text.TextRenderer import com.google.android.exoplayer2.text.TextRenderer
import com.google.android.exoplayer2.trackselection.DefaultTrackSelector import com.google.android.exoplayer2.trackselection.DefaultTrackSelector
import com.google.android.exoplayer2.trackselection.TrackSelectionOverride
import com.google.android.exoplayer2.trackselection.TrackSelector import com.google.android.exoplayer2.trackselection.TrackSelector
import com.google.android.exoplayer2.ui.SubtitleView import com.google.android.exoplayer2.ui.SubtitleView
import com.google.android.exoplayer2.upstream.* import com.google.android.exoplayer2.upstream.*
@ -219,43 +218,7 @@ class CS3IPlayer : IPlayer {
var currentSubtitles: SubtitleData? = null var currentSubtitles: SubtitleData? = null
private fun List<Tracks.Group>.getTrack(id: String?): Pair<TrackGroup, Int>? { override fun setMaxVideoSize(width: Int, height: Int) {
if (id == null) return null
// This beast of an expression does:
// 1. Filter all audio tracks
// 2. Get all formats in said audio tacks
// 3. Gets all ids of the formats
// 4. Filters to find the first audio track with the same id as the audio track we are looking for
// 5. Returns the media group and the index of the audio track in the group
return this.firstNotNullOfOrNull { group ->
(0 until group.mediaTrackGroup.length).map {
group.getTrackFormat(it) to it
}.firstOrNull { it.first.id == id }
?.let { group.mediaTrackGroup to it.second }
}
}
override fun setMaxVideoSize(width: Int, height: Int, id: String?) {
if (id != null) {
val videoTrack =
exoPlayer?.currentTracks?.groups?.filter { it.type == TRACK_TYPE_VIDEO }
?.getTrack(id)
if (videoTrack != null) {
exoPlayer?.trackSelectionParameters = exoPlayer?.trackSelectionParameters
?.buildUpon()
?.setOverrideForType(
TrackSelectionOverride(
videoTrack.first,
videoTrack.second
)
)
?.build()
?: return
return
}
}
exoPlayer?.trackSelectionParameters = exoPlayer?.trackSelectionParameters exoPlayer?.trackSelectionParameters = exoPlayer?.trackSelectionParameters
?.buildUpon() ?.buildUpon()
?.setMaxVideoSize(width, height) ?.setMaxVideoSize(width, height)
@ -263,29 +226,8 @@ class CS3IPlayer : IPlayer {
?: return ?: return
} }
override fun setPreferredAudioTrack(trackLanguage: String?, id: String?) { override fun setPreferredAudioTrack(trackLanguage: String?) {
preferredAudioTrackLanguage = trackLanguage preferredAudioTrackLanguage = trackLanguage
if (id != null) {
val audioTrack =
exoPlayer?.currentTracks?.groups?.filter { it.type == TRACK_TYPE_AUDIO }
?.getTrack(id)
if (audioTrack != null) {
exoPlayer?.trackSelectionParameters = exoPlayer?.trackSelectionParameters
?.buildUpon()
?.setOverrideForType(
TrackSelectionOverride(
audioTrack.first,
audioTrack.second
)
)
?.build()
?: return
return
}
}
exoPlayer?.trackSelectionParameters = exoPlayer?.trackSelectionParameters exoPlayer?.trackSelectionParameters = exoPlayer?.trackSelectionParameters
?.buildUpon() ?.buildUpon()
?.setPreferredAudioLanguage(trackLanguage) ?.setPreferredAudioLanguage(trackLanguage)
@ -297,11 +239,11 @@ class CS3IPlayer : IPlayer {
/** /**
* Gets all supported formats in a list * Gets all supported formats in a list
* */ * */
private fun List<Tracks.Group>.getFormats(): List<Pair<Format, Int>> { private fun List<TracksInfo.TrackGroupInfo>.getFormats(): List<Format> {
return this.map { return this.map {
(0 until it.mediaTrackGroup.length).mapNotNull { i -> (0 until it.trackGroup.length).mapNotNull { i ->
if (it.isSupported) if (it.isSupported)
it.mediaTrackGroup.getFormat(i) to i it.trackGroup.getFormat(i) // to it.isSelected
else null else null
} }
}.flatten() }.flatten()
@ -328,12 +270,11 @@ class CS3IPlayer : IPlayer {
} }
override fun getVideoTracks(): CurrentTracks { override fun getVideoTracks(): CurrentTracks {
val allTracks = exoPlayer?.currentTracks?.groups ?: emptyList() val allTracks = exoPlayer?.currentTracksInfo?.trackGroupInfos ?: emptyList()
val videoTracks = allTracks.filter { it.type == TRACK_TYPE_VIDEO } val videoTracks = allTracks.filter { it.trackType == TRACK_TYPE_VIDEO }.getFormats()
.getFormats() .map { it.toVideoTrack() }
.map { it.first.toVideoTrack() } val audioTracks = allTracks.filter { it.trackType == TRACK_TYPE_AUDIO }.getFormats()
val audioTracks = allTracks.filter { it.type == TRACK_TYPE_AUDIO }.getFormats() .map { it.toAudioTrack() }
.map { it.first.toAudioTrack() }
return CurrentTracks( return CurrentTracks(
exoPlayer?.videoFormat?.toVideoTrack(), exoPlayer?.videoFormat?.toVideoTrack(),
@ -670,12 +611,7 @@ class CS3IPlayer : IPlayer {
} else it } else it
}.toTypedArray() }.toTypedArray()
} }
.setTrackSelector( .setTrackSelector(trackSelector ?: getTrackSelector(context, maxVideoHeight))
trackSelector ?: getTrackSelector(
context,
maxVideoHeight
)
)
.setLoadControl( .setLoadControl(
DefaultLoadControl.Builder() DefaultLoadControl.Builder()
.setTargetBufferBytes( .setTargetBufferBytes(
@ -845,7 +781,10 @@ class CS3IPlayer : IPlayer {
isPlaying = exo.isPlaying isPlaying = exo.isPlaying
} }
exoPlayer?.addListener(object : Player.Listener { exoPlayer?.addListener(object : Player.Listener {
override fun onTracksChanged(tracks: Tracks) { /**
* Records the current used subtitle/track. Needed as exoplayer seems to have loose track language selection.
* */
override fun onTracksInfoChanged(tracksInfo: TracksInfo) {
fun Format.isSubtitle(): Boolean { fun Format.isSubtitle(): Boolean {
return this.sampleMimeType?.contains("video/") == false && return this.sampleMimeType?.contains("video/") == false &&
this.sampleMimeType?.contains("audio/") == false this.sampleMimeType?.contains("audio/") == false
@ -853,17 +792,17 @@ class CS3IPlayer : IPlayer {
normalSafeApiCall { normalSafeApiCall {
exoPlayerSelectedTracks = exoPlayerSelectedTracks =
tracks.groups.mapNotNull { tracksInfo.trackGroupInfos.mapNotNull {
val format = it.mediaTrackGroup.getFormat(0) val format = it.trackGroup.getFormat(0)
if (format.isSubtitle()) if (format.isSubtitle())
format.language?.let { lang -> lang to it.isSelected } format.language?.let { lang -> lang to it.isSelected }
else null else null
} }
val exoPlayerReportedTracks = tracks.groups.mapNotNull { val exoPlayerReportedTracks = tracksInfo.trackGroupInfos.mapNotNull {
// Filter out unsupported tracks // Filter out unsupported tracks
if (it.isSupported) if (it.isSupported)
it.mediaTrackGroup.getFormat(0) it.trackGroup.getFormat(0)
else else
null null
}.mapNotNull { }.mapNotNull {
@ -888,6 +827,7 @@ class CS3IPlayer : IPlayer {
onTracksInfoChanged?.invoke() onTracksInfoChanged?.invoke()
subtitlesUpdates?.invoke() subtitlesUpdates?.invoke()
} }
super.onTracksInfoChanged(tracksInfo)
} }
override fun onPlayerStateChanged(playWhenReady: Boolean, playbackState: Int) { override fun onPlayerStateChanged(playWhenReady: Boolean, playbackState: Int) {

View file

@ -796,16 +796,15 @@ class GeneratorPlayer : FullScreenPlayer() {
} }
tracksDialog.apply_btt?.setOnClickListener { tracksDialog.apply_btt?.setOnClickListener {
val currentTrack = currentAudioTracks.getOrNull(audioIndexStart)
player.setPreferredAudioTrack( player.setPreferredAudioTrack(
currentTrack?.language, currentTrack?.id currentAudioTracks.getOrNull(audioIndexStart)?.language
) )
val currentVideo = currentVideoTracks.getOrNull(videoIndex) val currentVideo = currentVideoTracks.getOrNull(videoIndex)
val width = currentVideo?.width ?: NO_VALUE val width = currentVideo?.width ?: NO_VALUE
val height = currentVideo?.height ?: NO_VALUE val height = currentVideo?.height ?: NO_VALUE
if (width != NO_VALUE && height != NO_VALUE) { if (width != NO_VALUE && height != NO_VALUE) {
player.setMaxVideoSize(width, height, currentVideo?.id) player.setMaxVideoSize(width, height)
} }
tracksDialog.dismissSafe(activity) tracksDialog.dismissSafe(activity)

View file

@ -161,9 +161,9 @@ interface IPlayer {
fun getVideoTracks(): CurrentTracks fun getVideoTracks(): CurrentTracks
/** If no parameters are set it'll default to no set size, Specifying the id allows for track overrides to force the player to pick the quality. */ /** If no parameters are set it'll default to no set size */
fun setMaxVideoSize(width: Int = Int.MAX_VALUE, height: Int = Int.MAX_VALUE, id: String? = null) fun setMaxVideoSize(width: Int = Int.MAX_VALUE, height: Int = Int.MAX_VALUE)
/** If no trackLanguage is set it'll default to first track. Specifying the id allows for track overrides as the language can be identical. */ /** If no trackLanguage is set it'll default to first track */
fun setPreferredAudioTrack(trackLanguage: String?, id: String? = null) fun setPreferredAudioTrack(trackLanguage: String?)
} }

View file

@ -75,7 +75,7 @@ open class NonFinalTextRenderer @JvmOverloads constructor(
return TAG return TAG
} }
// @RendererCapabilities.Capabilities @RendererCapabilities.Capabilities
override fun supportsFormat(format: Format): Int { override fun supportsFormat(format: Format): Int {
return if (decoderFactory.supportsFormat(format)) { return if (decoderFactory.supportsFormat(format)) {
RendererCapabilities.create( RendererCapabilities.create(
@ -202,8 +202,7 @@ open class NonFinalTextRenderer @JvmOverloads constructor(
return return
} }
// Try and read the next subtitle from the source. // Try and read the next subtitle from the source.
// @ReadDataResult @ReadDataResult val result =
val result =
readSource(formatHold, nextInputBuffer, /* readFlags= */0) readSource(formatHold, nextInputBuffer, /* readFlags= */0)
if (result == C.RESULT_BUFFER_READ) { if (result == C.RESULT_BUFFER_READ) {
if (nextInputBuffer.isEndOfStream) { if (nextInputBuffer.isEndOfStream) {

View file

@ -49,7 +49,7 @@ data class SaveCaptionStyle(
@JsonProperty("foregroundColor") var foregroundColor: Int, @JsonProperty("foregroundColor") var foregroundColor: Int,
@JsonProperty("backgroundColor") var backgroundColor: Int, @JsonProperty("backgroundColor") var backgroundColor: Int,
@JsonProperty("windowColor") var windowColor: Int, @JsonProperty("windowColor") var windowColor: Int,
// @CaptionStyleCompat.EdgeType @CaptionStyleCompat.EdgeType
@JsonProperty("edgeType") var edgeType: Int, @JsonProperty("edgeType") var edgeType: Int,
@JsonProperty("edgeColor") var edgeColor: Int, @JsonProperty("edgeColor") var edgeColor: Int,
@FontRes @FontRes

View file

@ -20,13 +20,10 @@ class CastOptionsProvider : OptionsProvider {
MediaIntentReceiver.ACTION_FORWARD, MediaIntentReceiver.ACTION_FORWARD,
MediaIntentReceiver.ACTION_STOP_CASTING MediaIntentReceiver.ACTION_STOP_CASTING
) )
val name = ControllerActivity::class.qualifiedName!!
val compatButtonAction = intArrayOf(1, 3) val compatButtonAction = intArrayOf(1, 3)
val notificationOptions = val notificationOptions =
NotificationOptions.Builder() NotificationOptions.Builder()
.setTargetActivityClassName(name) .setTargetActivityClassName(ControllerActivity::class.qualifiedName)
.setActions(buttonActions, compatButtonAction) .setActions(buttonActions, compatButtonAction)
.setForward30DrawableResId(R.drawable.go_forward_30) .setForward30DrawableResId(R.drawable.go_forward_30)
.setRewind30DrawableResId(R.drawable.go_back_30) .setRewind30DrawableResId(R.drawable.go_back_30)
@ -35,7 +32,7 @@ class CastOptionsProvider : OptionsProvider {
val mediaOptions = CastMediaOptions.Builder() val mediaOptions = CastMediaOptions.Builder()
.setNotificationOptions(notificationOptions) .setNotificationOptions(notificationOptions)
.setExpandedControllerActivityClassName(name) .setExpandedControllerActivityClassName(ControllerActivity::class.qualifiedName)
.build() .build()
return CastOptions.Builder() return CastOptions.Builder()
@ -47,7 +44,7 @@ class CastOptionsProvider : OptionsProvider {
.build() .build()
} }
override fun getAdditionalSessionProviders(p0: Context): MutableList<SessionProvider> { override fun getAdditionalSessionProviders(p0: Context?): MutableList<SessionProvider> {
return Collections.emptyList() return Collections.emptyList()
} }
} }