Correct callback

This commit is contained in:
Blatzar 2022-08-31 21:56:39 +02:00
parent f6a70c5133
commit d19a65f2e5
5 changed files with 15 additions and 1 deletions

View file

@ -99,6 +99,10 @@ abstract class AbstractPlayerFragment(
throw NotImplementedError()
}
open fun onTracksInfoChanged() {
throw NotImplementedError()
}
open fun exitedPipMode() {
throw NotImplementedError()
}
@ -369,6 +373,7 @@ abstract class AbstractPlayerFragment(
),
subtitlesUpdates = ::subtitlesChanged,
embeddedSubtitlesFetched = ::embeddedSubtitlesFetched,
onTracksInfoChanged = ::onTracksInfoChanged
)
if (player is CS3IPlayer) {

View file

@ -113,6 +113,7 @@ class CS3IPlayer : IPlayer {
private var playerUpdated: ((Any?) -> Unit)? = null
private var embeddedSubtitlesFetched: ((List<SubtitleData>) -> Unit)? = null
private var onTracksInfoChanged: (() -> Unit)? = null
override fun releaseCallbacks() {
playerUpdated = null
@ -125,7 +126,7 @@ class CS3IPlayer : IPlayer {
nextEpisode = null
prevEpisode = null
subtitlesUpdates = null
embeddedSubtitlesFetched = null
onTracksInfoChanged = null
requestSubtitleUpdate = null
}
@ -141,6 +142,7 @@ class CS3IPlayer : IPlayer {
prevEpisode: (() -> Unit)?,
subtitlesUpdates: (() -> Unit)?,
embeddedSubtitlesFetched: ((List<SubtitleData>) -> Unit)?,
onTracksInfoChanged: (() -> Unit)?,
) {
this.playerUpdated = playerUpdated
this.updateIsPlaying = updateIsPlaying
@ -153,6 +155,7 @@ class CS3IPlayer : IPlayer {
this.prevEpisode = prevEpisode
this.subtitlesUpdates = subtitlesUpdates
this.embeddedSubtitlesFetched = embeddedSubtitlesFetched
this.onTracksInfoChanged = onTracksInfoChanged
}
// I know, this is not a perfect solution, however it works for fixing subs
@ -818,6 +821,7 @@ class CS3IPlayer : IPlayer {
}
embeddedSubtitlesFetched?.invoke(exoPlayerReportedTracks)
onTracksInfoChanged?.invoke()
subtitlesUpdates?.invoke()
}
super.onTracksInfoChanged(tracksInfo)

View file

@ -113,6 +113,9 @@ class GeneratorPlayer : FullScreenPlayer() {
override fun embeddedSubtitlesFetched(subtitles: List<SubtitleData>) {
viewModel.addSubtitles(subtitles.toSet())
}
override fun onTracksInfoChanged() {
val tracks = player.getVideoTracks()
player_tracks_btt?.isVisible = tracks.allVideoTracks.size > 1 || tracks.allAudioTracks.size > 1
}

View file

@ -123,6 +123,7 @@ interface IPlayer {
prevEpisode: (() -> Unit)? = null, // this is used by the player to load the previous episode
subtitlesUpdates: (() -> Unit)? = null, // callback from player to inform that subtitles have updated in some way
embeddedSubtitlesFetched: ((List<SubtitleData>) -> Unit)? = null, // callback from player to give all embedded subtitles
onTracksInfoChanged: (() -> Unit)? = null, // Callback when tracks are changed, used for UI changes
)
fun releaseCallbacks()

View file

@ -82,6 +82,7 @@ open class ResultTrailerPlayer : com.lagradost.cloudstream3.ui.player.FullScreen
override fun subtitlesChanged() {}
override fun embeddedSubtitlesFetched(subtitles: List<SubtitleData>) {}
override fun onTracksInfoChanged() {}
override fun exitedPipMode() {}