Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
151 changes: 137 additions & 14 deletions shared/src/androidMain/kotlin/dev/bilby/player/AudioPlaybackService.kt

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class BilbyMediaSourceFactory(

private const val EXTRA_ITEM_CID = "cid"
private const val EXTRA_ITEM_START_MS = "startMs"
private const val EXTRA_ITEM_FALLBACK_START_MS = "fallbackStartMs"
private const val EXTRA_ITEM_LOAD = "load"
private const val EXTRA_ITEM_ROOM_ID = "roomId"
private const val EXTRA_ITEM_LIVE_QN = "liveQn"
Expand All @@ -65,6 +66,10 @@ val MediaItem.cidHint: Long
val MediaItem.startPositionHint: Long?
get() = requestMetadata.extras?.getLong(EXTRA_ITEM_START_MS, -1L)?.takeIf { it >= 0 }

/** 一次性本机续播兜底位置(毫秒),仅在云端进度缺失或落后时生效。 */
val MediaItem.fallbackStartPositionHint: Long?
get() = requestMetadata.extras?.getLong(EXTRA_ITEM_FALLBACK_START_MS, -1L)?.takeIf { it > 0 }

/**
* 第几次装载这一条。**"要不要重新取流"就是靠它表达的。**
*
Expand Down Expand Up @@ -111,13 +116,15 @@ val MediaItem.isLive: Boolean
fun QueueItem.toMediaItem(
requestedCid: Long = 0,
startPositionMillis: Long? = null,
fallbackStartPositionMillis: Long? = null,
loadNonce: Int = 0,
): MediaItem = MediaItem.Builder()
.setMediaId(bvid)
.setRequestMetadata(
loadParams(
requestedCid = requestedCid,
startPositionMillis = startPositionMillis,
fallbackStartPositionMillis = fallbackStartPositionMillis,
loadNonce = loadNonce,
)
)
Expand Down Expand Up @@ -158,13 +165,15 @@ fun MediaItem.withLoadParams(
loadNonce: Int,
requestedCid: Long = 0,
startPositionMillis: Long? = null,
fallbackStartPositionMillis: Long? = null,
liveQn: Int = this.liveQn,
onlyAudio: Boolean = this.liveOnlyAudio,
): MediaItem = buildUpon()
.setRequestMetadata(
loadParams(
requestedCid = requestedCid,
startPositionMillis = startPositionMillis,
fallbackStartPositionMillis = fallbackStartPositionMillis,
loadNonce = loadNonce,
roomId = liveRoomId,
liveQn = liveQn,
Expand All @@ -176,6 +185,7 @@ fun MediaItem.withLoadParams(
private fun loadParams(
requestedCid: Long = 0,
startPositionMillis: Long? = null,
fallbackStartPositionMillis: Long? = null,
loadNonce: Int = 0,
roomId: Long = 0,
liveQn: Int = 0,
Expand All @@ -185,6 +195,7 @@ private fun loadParams(
Bundle().apply {
putLong(EXTRA_ITEM_CID, requestedCid)
putLong(EXTRA_ITEM_START_MS, startPositionMillis ?: -1L)
putLong(EXTRA_ITEM_FALLBACK_START_MS, fallbackStartPositionMillis ?: -1L)
putInt(EXTRA_ITEM_LOAD, loadNonce)
putLong(EXTRA_ITEM_ROOM_ID, roomId)
putInt(EXTRA_ITEM_LIVE_QN, liveQn)
Expand Down
9 changes: 9 additions & 0 deletions shared/src/commonMain/composeResources/values-en/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -998,6 +998,15 @@
<string name="feed_burst_expand_rest">Show %1$d more uploads</string>
<string name="feed_live_count_badge">%1$d live</string>
<string name="collection_total_count">%1$d videos</string>
<string name="collection_watched_count">%1$d watched</string>
<string name="collection_continue_watching">Continue watching</string>
<string name="collection_continue_progress">Left off at %1$s</string>
<string name="collection_continue_next">Next episode</string>
<string name="collection_continue_finished">Watched</string>
<string name="settings_clear_collection_progress">Clear collection watch progress</string>
<string name="settings_clear_collection_progress_subtitle">Remove locally saved collection and series progress</string>
<string name="settings_clear_collection_progress_message">Remove all locally saved collection and series watch progress?</string>
<string name="settings_collection_progress_count">%1$d saved</string>
<string name="agent_steps_count">%1$d steps searched</string>
<!-- Library in-page search -->
<string name="history_search_hint">Search watch history</string>
Expand Down
9 changes: 9 additions & 0 deletions shared/src/commonMain/composeResources/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1060,6 +1060,15 @@
<string name="feed_burst_expand_rest">展开其余 %1$d 条连发</string>
<string name="feed_live_count_badge">%1$d 直播</string>
<string name="collection_total_count">共 %1$d 个视频</string>
<string name="collection_watched_count">已看 %1$d</string>
<string name="collection_continue_watching">继续观看</string>
<string name="collection_continue_progress">上次看到 %1$s</string>
<string name="collection_continue_next">下一集</string>
<string name="collection_continue_finished">已看完</string>
<string name="settings_clear_collection_progress">清除合集观看记录</string>
<string name="settings_clear_collection_progress_subtitle">清除本机保存的合集与系列观看进度</string>
<string name="settings_clear_collection_progress_message">清除本机保存的所有合集与系列观看进度?</string>
<string name="settings_collection_progress_count">%1$d 项</string>
<string name="agent_steps_count">已检索 %1$d 步</string>
<!-- 媒体库页内搜索 -->
<string name="history_search_hint">搜索历史记录</string>
Expand Down
14 changes: 13 additions & 1 deletion shared/src/commonMain/kotlin/dev/bilby/AppContainer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import dev.bilby.data.DynamicFeedStore
import dev.bilby.data.DynamicRepository
import dev.bilby.data.FingerprintStore
import dev.bilby.danmaku.DanmakuRepository
import dev.bilby.data.CollectionProgressStore
import dev.bilby.data.CommentRepository
import dev.bilby.data.EmoteRepository
import dev.bilby.data.FavRepository
Expand Down Expand Up @@ -123,7 +124,9 @@ class AppContainer(
*
* 没有 cookie 刷新这一环:凭据过期就重新扫码,理由见 notes/auth-model.md §7。
*/
val tvLoginRepository: TvLoginRepository by lazy { TvLoginRepository(biliClient, settings, deviceFingerprint) }
val tvLoginRepository: TvLoginRepository by lazy {
TvLoginRepository(biliClient, settings, deviceFingerprint, collectionProgressStore)
}


val dynamicRepository: DynamicRepository by lazy { DynamicRepository(biliClient) }
Expand Down Expand Up @@ -173,6 +176,15 @@ class AppContainer(

val historyRepository: HistoryRepository by lazy { HistoryRepository(biliClient) }

/** 合集与系列观看进度独立 JSON 存储,脱离 Room 破坏性迁移生命周期。 */
val collectionProgressStore: CollectionProgressStore by lazy {
CollectionProgressStore(
file = java.io.File(platform.filesDir, "collection-progress.json"),
json = json,
isHistoryPaused = { historyRepository.lastKnownPaused == true },
)
}

/** 消息中心(回复/@/赞/通知)与私信。两组接口分属两个主机,见它自己的说明。 */
val messageRepository: MessageRepository by lazy { MessageRepository(biliClient) }

Expand Down
Loading