初始化 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,24 @@
|
||||
plugins {
|
||||
id("com.android.library")
|
||||
kotlin("android")
|
||||
}
|
||||
|
||||
android {
|
||||
namespace = "com.ttstd.player.renderandroid"
|
||||
compileSdk = 37
|
||||
|
||||
defaultConfig {
|
||||
minSdk = 23
|
||||
}
|
||||
|
||||
compileOptions {
|
||||
sourceCompatibility = JavaVersion.VERSION_17
|
||||
targetCompatibility = JavaVersion.VERSION_17
|
||||
}
|
||||
}
|
||||
|
||||
kotlin { jvmToolchain(17) }
|
||||
|
||||
dependencies {
|
||||
api(project(":player-android-api"))
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
<manifest />
|
||||
@@ -0,0 +1,50 @@
|
||||
package com.ttstd.player.render
|
||||
|
||||
import android.graphics.SurfaceTexture
|
||||
import android.view.Surface
|
||||
import android.view.SurfaceHolder
|
||||
import android.view.SurfaceView
|
||||
import android.view.TextureView
|
||||
import com.ttstd.player.android.AndroidVideoOutput
|
||||
|
||||
/** 主线程使用。close 解除回调和输出绑定;SurfaceView 的 Surface 所有权属于系统。 */
|
||||
class SurfaceViewBinding(private val view: SurfaceView, private val output: AndroidVideoOutput) : AutoCloseable, SurfaceHolder.Callback {
|
||||
private var surface: Surface? = null
|
||||
init {
|
||||
view.holder.addCallback(this)
|
||||
if (view.holder.surface.isValid) surfaceCreated(view.holder)
|
||||
}
|
||||
override fun surfaceCreated(holder: SurfaceHolder) {
|
||||
surface = holder.surface
|
||||
output.attachSurface(holder.surface)
|
||||
}
|
||||
override fun surfaceChanged(holder: SurfaceHolder, format: Int, width: Int, height: Int) = Unit
|
||||
override fun surfaceDestroyed(holder: SurfaceHolder) { detach() }
|
||||
private fun detach() { surface?.let(output::detachSurface); surface = null }
|
||||
override fun close() { view.holder.removeCallback(this); detach() }
|
||||
}
|
||||
|
||||
/** 独占 TextureView listener。仅释放自己创建的 Surface,SurfaceTexture 交回 View 管理。 */
|
||||
class TextureViewBinding(private val view: TextureView, private val output: AndroidVideoOutput) : AutoCloseable, TextureView.SurfaceTextureListener {
|
||||
private var surface: Surface? = null
|
||||
init {
|
||||
require(view.surfaceTextureListener == null) { "TextureView 已绑定其他 listener" }
|
||||
view.surfaceTextureListener = this
|
||||
if (view.isAvailable) view.surfaceTexture?.let { onSurfaceTextureAvailable(it, view.width, view.height) }
|
||||
}
|
||||
override fun onSurfaceTextureAvailable(texture: SurfaceTexture, width: Int, height: Int) {
|
||||
detach()
|
||||
surface = Surface(texture).also { output.attachSurface(it) }
|
||||
}
|
||||
override fun onSurfaceTextureSizeChanged(texture: SurfaceTexture, width: Int, height: Int) = Unit
|
||||
override fun onSurfaceTextureUpdated(texture: SurfaceTexture) = Unit
|
||||
override fun onSurfaceTextureDestroyed(texture: SurfaceTexture): Boolean { detach(); return true }
|
||||
private fun detach() {
|
||||
surface?.let { output.detachSurface(it); it.release() }
|
||||
surface = null
|
||||
}
|
||||
override fun close() {
|
||||
if (view.surfaceTextureListener === this) view.surfaceTextureListener = null
|
||||
detach()
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user