初始化 TTVideoPlayer 工程:模块化播放框架、同同影音 App 与文档
Media3 内核播放框架(player-api/core/media3/source/render/lifecycle/telemetry)、 WebDAV/SMB/Jellyfin 来源、DLNA/Google Cast 投屏、RTMP 原生库与完整 App。
This commit is contained in:
commit
922ec80bcc
147 files changed
+20169
No files matched your search
@@ -0,0 +1,77 @@
|
||||
package com.ttstd.player.library
|
||||
|
||||
import com.ttstd.player.api.*
|
||||
|
||||
enum class LibraryKind { WEBDAV, SMB, JELLYFIN }
|
||||
|
||||
/** 账户配置只存储于宿主私有加密仓库;禁止把该对象输出至日志。 */
|
||||
class LibraryAccount(
|
||||
val id: String,
|
||||
val name: String,
|
||||
val kind: LibraryKind,
|
||||
val endpoint: String,
|
||||
val username: String = "",
|
||||
val password: String = "",
|
||||
val domain: String = "",
|
||||
) {
|
||||
override fun toString() = "LibraryAccount(id=$id, kind=$kind, credentials=REDACTED)"
|
||||
}
|
||||
|
||||
data class LibraryEntry(
|
||||
val id: String,
|
||||
val name: String,
|
||||
val isFolder: Boolean,
|
||||
val size: Long? = null,
|
||||
val version: String = "",
|
||||
val resumeMs: Long = 0,
|
||||
)
|
||||
data class LibraryPage(val entries: List<LibraryEntry>, val nextOffset: Int? = null)
|
||||
|
||||
/** 来源适配负责授权、浏览和播放协商,不引用播放器内核。 */
|
||||
interface MediaLibrary {
|
||||
val account: LibraryAccount
|
||||
suspend fun list(folderId: String = "", offset: Int = 0): LibraryPage
|
||||
suspend fun resolve(entry: LibraryEntry, options: LibraryPlaybackOptions = LibraryPlaybackOptions()): LibraryPlayback
|
||||
}
|
||||
data class LibraryPlaybackOptions(val startPositionMs: Long = 0, val maxBitrate: Int = 4_000_000, val maxWidth: Int = 1280, val maxHeight: Int = 720)
|
||||
|
||||
/** 观看进度上报与解码独立;服务端出错不得阻塞本地播放。 */
|
||||
interface LibraryPlaybackSession {
|
||||
suspend fun started(positionMs: Long)
|
||||
suspend fun progress(positionMs: Long, paused: Boolean)
|
||||
suspend fun stopped(positionMs: Long)
|
||||
}
|
||||
data class LibraryPlayback(
|
||||
val request: PlaybackRequest,
|
||||
val stableId: String,
|
||||
val title: String,
|
||||
val contentLength: Long? = null,
|
||||
val session: LibraryPlaybackSession? = null,
|
||||
val subtitles: List<ExternalSubtitle> = request.subtitles,
|
||||
/** 服务端已提供无需自定义请求头的接收端 URL 时,可直接投屏。 */
|
||||
val receiverRequest: PlaybackRequest? = null,
|
||||
/** 从指定位置启动的服务端转码流,其本地时轴可能从零开始。 */
|
||||
val positionOffsetMs: Long = 0,
|
||||
/** 重新取得临时地址或重新协商转码;位置为原媒体的绝对毫秒。 */
|
||||
val refresh: (suspend (Long) -> LibraryPlayback)? = null,
|
||||
val originalDurationMs: Long? = null,
|
||||
)
|
||||
|
||||
class LibraryException(message: String) : Exception(message)
|
||||
|
||||
object LibraryFiles {
|
||||
private val videos = setOf("mp4", "mkv", "webm", "mov", "m4v", "avi", "ts", "m2ts", "flv", "wmv", "mpg", "mpeg")
|
||||
fun isVideo(name: String) = name.substringAfterLast('.', "").lowercase() in videos
|
||||
fun subtitleMime(name: String): String? = when (name.substringAfterLast('.', "").lowercase()) {
|
||||
"srt" -> "application/x-subrip"
|
||||
"vtt" -> "text/vtt"
|
||||
"ass", "ssa" -> "text/x-ssa"
|
||||
else -> null
|
||||
}
|
||||
/** 包含 movie.srt、movie.zh.srt,不把 movie2.srt 错配给 movie.mp4。 */
|
||||
fun matchesSubtitle(video: String, subtitle: String): Boolean {
|
||||
val base = video.substringBeforeLast('.', video)
|
||||
val stem = subtitle.substringBeforeLast('.', subtitle)
|
||||
return subtitleMime(subtitle) != null && (stem.equals(base, true) || stem.startsWith("$base.", true))
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.ttstd.player.library
|
||||
import org.junit.Assert.*
|
||||
import org.junit.Test
|
||||
|
||||
class LibraryFilesTest {
|
||||
@Test fun subtitleMatchingDoesNotCrossMovieNames() {
|
||||
assertTrue(LibraryFiles.matchesSubtitle("Movie.MKV", "movie.zh.srt"))
|
||||
assertTrue(LibraryFiles.matchesSubtitle("电影.mp4", "电影.ass"))
|
||||
assertFalse(LibraryFiles.matchesSubtitle("movie.mp4", "movie2.srt"))
|
||||
assertFalse(LibraryFiles.matchesSubtitle("movie.mp4", "movie.mp4"))
|
||||
assertTrue(LibraryFiles.isVideo("A.M2TS"))
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user