Skip to content

Commit ef2c07b

Browse files
committed
fix: urls with timestamps don't work properly
1 parent 83e121b commit ef2c07b

2 files changed

Lines changed: 23 additions & 16 deletions

File tree

app/src/main/java/com/github/libretube/services/OnlinePlayerService.kt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ open class OnlinePlayerService : AbstractPlayerService() {
5050
// PlaylistId/ChannelId for autoplay
5151
private var playlistId: String? = null
5252
private var channelId: String? = null
53-
private var startTimestamp: Long? = null
53+
private var startTimestampSeconds: Long? = null
5454

5555
/**
5656
* The response that gets when called the Api.
@@ -105,7 +105,7 @@ open class OnlinePlayerService : AbstractPlayerService() {
105105
setVideoId(playerData.videoId)
106106
playlistId = playerData.playlistId
107107
channelId = playerData.channelId
108-
startTimestamp = playerData.timestamp
108+
startTimestampSeconds = playerData.timestamp
109109

110110
if (!playerData.keepQueue) PlayingQueue.clear()
111111

@@ -115,8 +115,8 @@ open class OnlinePlayerService : AbstractPlayerService() {
115115
override suspend fun startPlayback() {
116116
super.startPlayback()
117117

118-
val timestamp = startTimestamp ?: 0L
119-
startTimestamp = null
118+
val timestampMs = startTimestampSeconds?.times(1000) ?: 0L
119+
startTimestampSeconds = null
120120

121121
streams = withContext(Dispatchers.IO) {
122122
try {
@@ -152,16 +152,16 @@ open class OnlinePlayerService : AbstractPlayerService() {
152152
}
153153

154154
withContext(Dispatchers.Main) {
155-
playAudio(timestamp)
155+
playAudio(timestampMs)
156156
}
157157
}
158158

159-
private fun playAudio(seekToPosition: Long) {
159+
private fun playAudio(seekToPositionMs: Long) {
160160
setStreamSource()
161161

162162
// seek to the previous position if available
163-
if (seekToPosition != 0L) {
164-
exoPlayer?.seekTo(seekToPosition)
163+
if (seekToPositionMs != 0L) {
164+
exoPlayer?.seekTo(seekToPositionMs)
165165
} else if (watchPositionsEnabled) {
166166
DatabaseHelper.getWatchPositionBlocking(videoId)?.let {
167167
if (!DatabaseHelper.isVideoWatched(it, streams?.duration)) exoPlayer?.seekTo(it)

app/src/main/java/com/github/libretube/ui/dialogs/ShareDialog.kt

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -133,15 +133,22 @@ class ShareDialog : DialogFragment() {
133133
// only available for custom instances
134134
else -> customInstanceUrl!!.toString().trimEnd('/')
135135
}
136-
var url = when {
137-
shareObjectType == ShareObjectType.VIDEO && host == YOUTUBE_FRONTEND_URL -> "$YOUTUBE_SHORT_URL/$id"
138-
shareObjectType == ShareObjectType.VIDEO -> "$host/watch?v=$id"
139-
shareObjectType == ShareObjectType.PLAYLIST -> "$host/playlist?list=$id"
140-
else -> "$host/channel/$id"
141-
}
136+
val url = when (shareObjectType) {
137+
ShareObjectType.VIDEO -> {
138+
val queryParams = mutableListOf<String>()
139+
if (host != YOUTUBE_FRONTEND_URL) {
140+
queryParams.add("v=${id}")
141+
}
142+
if (binding.timeCodeSwitch.isChecked) {
143+
queryParams += "t=${binding.timeStamp.text}"
144+
}
145+
val baseUrl = if (host == YOUTUBE_FRONTEND_URL) "$YOUTUBE_SHORT_URL/$id" else "$host/watch"
142146

143-
if (shareObjectType == ShareObjectType.VIDEO && binding.timeCodeSwitch.isChecked) {
144-
url += "&t=${binding.timeStamp.text}"
147+
if (queryParams.isEmpty()) baseUrl
148+
else baseUrl + "?" + queryParams.joinToString("&")
149+
}
150+
ShareObjectType.PLAYLIST -> "$host/playlist?list=$id"
151+
else -> "$host/channel/$id"
145152
}
146153

147154
return url

0 commit comments

Comments
 (0)