Fix immediate transition to next video when starting player

This commit is contained in:
Bnyro 2023-06-30 15:56:31 +02:00
parent ada94e0bb4
commit 10c9978bc8
5 changed files with 43 additions and 15 deletions

View File

@ -63,8 +63,8 @@ data class Streams(
path = Paths.get(""),
url = subtitles.find {
it.code == subCode
}?.url?.let { ProxyHelper.unwrapUrl(it) },
),
}?.url?.let { ProxyHelper.unwrapUrl(it) }
)
)
}

View File

@ -23,7 +23,12 @@ object DashHelper {
val formats: MutableList<PipedStream> = mutableListOf()
)
fun createManifest(streams: Streams, supportsHdr: Boolean, audioOnly: Boolean = false, rewriteUrls: Boolean): String {
fun createManifest(
streams: Streams,
supportsHdr: Boolean,
audioOnly: Boolean = false,
rewriteUrls: Boolean
): String {
val builder = builderFactory.newDocumentBuilder()
val doc = builder.newDocument()
@ -137,7 +142,11 @@ object DashHelper {
return writer.toString()
}
private fun createAudioRepresentation(doc: Document, stream: PipedStream, rewriteUrls: Boolean): Element {
private fun createAudioRepresentation(
doc: Document,
stream: PipedStream,
rewriteUrls: Boolean
): Element {
val representation = doc.createElement("Representation")
representation.setAttribute("bandwidth", stream.bitrate.toString())
representation.setAttribute("codecs", stream.codec!!)
@ -167,7 +176,11 @@ object DashHelper {
return representation
}
private fun createVideoRepresentation(doc: Document, stream: PipedStream, rewriteUrls: Boolean): Element {
private fun createVideoRepresentation(
doc: Document,
stream: PipedStream,
rewriteUrls: Boolean
): Element {
val representation = doc.createElement("Representation")
representation.setAttribute("codecs", stream.codec!!)
representation.setAttribute("bandwidth", stream.bitrate.toString())

View File

@ -48,9 +48,13 @@ object ProxyHelper {
else -> true
}
fun unwrapImageUrl(url: String): String = if (
fun unwrapImageUrl(url: String) = if (
!PreferenceHelper.getBoolean(PreferenceKeys.DISABLE_VIDEO_IMAGE_PROXY, false)
) url else unwrapUrl(url)
) {
url
} else {
unwrapUrl(url)
}
/**
* Convert a proxied Piped url to a YouTube url that's not proxied

View File

@ -25,7 +25,6 @@ import com.github.libretube.api.obj.Streams
import com.github.libretube.constants.BACKGROUND_CHANNEL_ID
import com.github.libretube.constants.IntentData
import com.github.libretube.constants.PLAYER_NOTIFICATION_ID
import com.github.libretube.constants.PreferenceKeys
import com.github.libretube.db.DatabaseHolder.Database
import com.github.libretube.db.obj.WatchPosition
import com.github.libretube.enums.SbSkipOptions
@ -35,7 +34,6 @@ import com.github.libretube.extensions.toID
import com.github.libretube.helpers.PlayerHelper
import com.github.libretube.helpers.PlayerHelper.checkForSegments
import com.github.libretube.helpers.PlayerHelper.loadPlaybackParams
import com.github.libretube.helpers.PreferenceHelper
import com.github.libretube.helpers.ProxyHelper
import com.github.libretube.obj.PlayerNotificationData
import com.github.libretube.parcelable.PlayerData
@ -303,7 +301,12 @@ class OnlinePlayerService : LifecycleService() {
val (uri, mimeType) = if (streams.audioStreams.isNotEmpty()) {
val disableProxy = ProxyHelper.shouldDisableProxy(streams.videoStreams.first().url!!)
PlayerHelper.createDashSource(streams, this, true, disableProxy) to MimeTypes.APPLICATION_MPD
PlayerHelper.createDashSource(
streams,
this,
true,
disableProxy
) to MimeTypes.APPLICATION_MPD
} else {
ProxyHelper.unwrapStreamUrl(streams.hls.orEmpty()).toUri() to MimeTypes.APPLICATION_M3U8
}

View File

@ -155,7 +155,7 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
*/
private var sId: Int = 0
private var eId: Int = 0
private var transitioning = false
private var transitioning = true
/**
* for the player
@ -1305,9 +1305,17 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
false
) && streams.videoStreams.isNotEmpty() -> {
// only use the dash manifest generated by YT if either it's a livestream or no other source is available
val dashUri = if (streams.livestream && streams.dash != null) ProxyHelper.unwrapStreamUrl(streams.dash!!).toUri() else {
val shouldDisableProxy = ProxyHelper.shouldDisableProxy(streams.videoStreams.first().url!!)
PlayerHelper.createDashSource(streams, requireContext(), disableProxy = shouldDisableProxy)
val dashUri =
if (streams.livestream && streams.dash != null) ProxyHelper.unwrapStreamUrl(
streams.dash!!
).toUri() else {
val shouldDisableProxy =
ProxyHelper.shouldDisableProxy(streams.videoStreams.first().url!!)
PlayerHelper.createDashSource(
streams,
requireContext(),
disableProxy = shouldDisableProxy
)
}
dashUri to MimeTypes.APPLICATION_MPD