fix: urls with timestamps don't work properly

This commit is contained in:
Bnyro 2025-03-23 16:32:24 +01:00
parent 83e121beb9
commit ef2c07bf03
No known key found for this signature in database
2 changed files with 23 additions and 16 deletions

View File

@ -50,7 +50,7 @@ open class OnlinePlayerService : AbstractPlayerService() {
// PlaylistId/ChannelId for autoplay // PlaylistId/ChannelId for autoplay
private var playlistId: String? = null private var playlistId: String? = null
private var channelId: String? = null private var channelId: String? = null
private var startTimestamp: Long? = null private var startTimestampSeconds: Long? = null
/** /**
* The response that gets when called the Api. * The response that gets when called the Api.
@ -105,7 +105,7 @@ open class OnlinePlayerService : AbstractPlayerService() {
setVideoId(playerData.videoId) setVideoId(playerData.videoId)
playlistId = playerData.playlistId playlistId = playerData.playlistId
channelId = playerData.channelId channelId = playerData.channelId
startTimestamp = playerData.timestamp startTimestampSeconds = playerData.timestamp
if (!playerData.keepQueue) PlayingQueue.clear() if (!playerData.keepQueue) PlayingQueue.clear()
@ -115,8 +115,8 @@ open class OnlinePlayerService : AbstractPlayerService() {
override suspend fun startPlayback() { override suspend fun startPlayback() {
super.startPlayback() super.startPlayback()
val timestamp = startTimestamp ?: 0L val timestampMs = startTimestampSeconds?.times(1000) ?: 0L
startTimestamp = null startTimestampSeconds = null
streams = withContext(Dispatchers.IO) { streams = withContext(Dispatchers.IO) {
try { try {
@ -152,16 +152,16 @@ open class OnlinePlayerService : AbstractPlayerService() {
} }
withContext(Dispatchers.Main) { withContext(Dispatchers.Main) {
playAudio(timestamp) playAudio(timestampMs)
} }
} }
private fun playAudio(seekToPosition: Long) { private fun playAudio(seekToPositionMs: Long) {
setStreamSource() setStreamSource()
// seek to the previous position if available // seek to the previous position if available
if (seekToPosition != 0L) { if (seekToPositionMs != 0L) {
exoPlayer?.seekTo(seekToPosition) exoPlayer?.seekTo(seekToPositionMs)
} else if (watchPositionsEnabled) { } else if (watchPositionsEnabled) {
DatabaseHelper.getWatchPositionBlocking(videoId)?.let { DatabaseHelper.getWatchPositionBlocking(videoId)?.let {
if (!DatabaseHelper.isVideoWatched(it, streams?.duration)) exoPlayer?.seekTo(it) if (!DatabaseHelper.isVideoWatched(it, streams?.duration)) exoPlayer?.seekTo(it)

View File

@ -133,15 +133,22 @@ class ShareDialog : DialogFragment() {
// only available for custom instances // only available for custom instances
else -> customInstanceUrl!!.toString().trimEnd('/') else -> customInstanceUrl!!.toString().trimEnd('/')
} }
var url = when { val url = when (shareObjectType) {
shareObjectType == ShareObjectType.VIDEO && host == YOUTUBE_FRONTEND_URL -> "$YOUTUBE_SHORT_URL/$id" ShareObjectType.VIDEO -> {
shareObjectType == ShareObjectType.VIDEO -> "$host/watch?v=$id" val queryParams = mutableListOf<String>()
shareObjectType == ShareObjectType.PLAYLIST -> "$host/playlist?list=$id" if (host != YOUTUBE_FRONTEND_URL) {
else -> "$host/channel/$id" queryParams.add("v=${id}")
} }
if (binding.timeCodeSwitch.isChecked) {
queryParams += "t=${binding.timeStamp.text}"
}
val baseUrl = if (host == YOUTUBE_FRONTEND_URL) "$YOUTUBE_SHORT_URL/$id" else "$host/watch"
if (shareObjectType == ShareObjectType.VIDEO && binding.timeCodeSwitch.isChecked) { if (queryParams.isEmpty()) baseUrl
url += "&t=${binding.timeStamp.text}" else baseUrl + "?" + queryParams.joinToString("&")
}
ShareObjectType.PLAYLIST -> "$host/playlist?list=$id"
else -> "$host/channel/$id"
} }
return url return url