diff --git a/app/src/main/java/com/github/libretube/services/OnlinePlayerService.kt b/app/src/main/java/com/github/libretube/services/OnlinePlayerService.kt index 938220638..7a0db3d5f 100644 --- a/app/src/main/java/com/github/libretube/services/OnlinePlayerService.kt +++ b/app/src/main/java/com/github/libretube/services/OnlinePlayerService.kt @@ -50,7 +50,7 @@ open class OnlinePlayerService : AbstractPlayerService() { // PlaylistId/ChannelId for autoplay private var playlistId: 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. @@ -105,7 +105,7 @@ open class OnlinePlayerService : AbstractPlayerService() { setVideoId(playerData.videoId) playlistId = playerData.playlistId channelId = playerData.channelId - startTimestamp = playerData.timestamp + startTimestampSeconds = playerData.timestamp if (!playerData.keepQueue) PlayingQueue.clear() @@ -115,8 +115,8 @@ open class OnlinePlayerService : AbstractPlayerService() { override suspend fun startPlayback() { super.startPlayback() - val timestamp = startTimestamp ?: 0L - startTimestamp = null + val timestampMs = startTimestampSeconds?.times(1000) ?: 0L + startTimestampSeconds = null streams = withContext(Dispatchers.IO) { try { @@ -152,16 +152,16 @@ open class OnlinePlayerService : AbstractPlayerService() { } withContext(Dispatchers.Main) { - playAudio(timestamp) + playAudio(timestampMs) } } - private fun playAudio(seekToPosition: Long) { + private fun playAudio(seekToPositionMs: Long) { setStreamSource() // seek to the previous position if available - if (seekToPosition != 0L) { - exoPlayer?.seekTo(seekToPosition) + if (seekToPositionMs != 0L) { + exoPlayer?.seekTo(seekToPositionMs) } else if (watchPositionsEnabled) { DatabaseHelper.getWatchPositionBlocking(videoId)?.let { if (!DatabaseHelper.isVideoWatched(it, streams?.duration)) exoPlayer?.seekTo(it) diff --git a/app/src/main/java/com/github/libretube/ui/dialogs/ShareDialog.kt b/app/src/main/java/com/github/libretube/ui/dialogs/ShareDialog.kt index 4adabea05..dd176a8f6 100644 --- a/app/src/main/java/com/github/libretube/ui/dialogs/ShareDialog.kt +++ b/app/src/main/java/com/github/libretube/ui/dialogs/ShareDialog.kt @@ -133,15 +133,22 @@ class ShareDialog : DialogFragment() { // only available for custom instances else -> customInstanceUrl!!.toString().trimEnd('/') } - var url = when { - shareObjectType == ShareObjectType.VIDEO && host == YOUTUBE_FRONTEND_URL -> "$YOUTUBE_SHORT_URL/$id" - shareObjectType == ShareObjectType.VIDEO -> "$host/watch?v=$id" - shareObjectType == ShareObjectType.PLAYLIST -> "$host/playlist?list=$id" - else -> "$host/channel/$id" - } + val url = when (shareObjectType) { + ShareObjectType.VIDEO -> { + val queryParams = mutableListOf() + if (host != YOUTUBE_FRONTEND_URL) { + 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) { - url += "&t=${binding.timeStamp.text}" + if (queryParams.isEmpty()) baseUrl + else baseUrl + "?" + queryParams.joinToString("&") + } + ShareObjectType.PLAYLIST -> "$host/playlist?list=$id" + else -> "$host/channel/$id" } return url