...
This commit is contained in:
parent
ac1c0b12b3
commit
b64df76c90
@ -83,7 +83,9 @@ class DocumentViewerActivity : AppCompatActivity() {
|
||||
}
|
||||
override fun onSwipeLeft(count: Int) { pagedLayout.doNext() }
|
||||
override fun onSwipeRight(count: Int) { pagedLayout.doPrev() }
|
||||
override fun onLongClick() { finish() } // 잠깐 확인용이므로 롱클릭 시 종료
|
||||
override fun onLongClick() {
|
||||
// finish()
|
||||
} // 잠깐 확인용이므로 롱클릭 시 종료
|
||||
override fun onTimeoverTouch() {}
|
||||
override fun onSwipeDown(count: Int) {}
|
||||
override fun onSwipeUp(count: Int) {}
|
||||
|
||||
@ -191,6 +191,81 @@ class PlayerActivity : AppCompatActivity(), TextureView.SurfaceTextureListener {
|
||||
private lateinit var tvTime: TextView
|
||||
private var uiUpdateJob: Job? = null
|
||||
private var isUserSeeking = false
|
||||
private fun setupSyncControls(root: FrameLayout) {
|
||||
val topControlLayout = android.widget.LinearLayout(this).apply {
|
||||
orientation = android.widget.LinearLayout.HORIZONTAL
|
||||
gravity = Gravity.CENTER
|
||||
setPadding(0, 20, 0, 0)
|
||||
}
|
||||
|
||||
// [ -0.5s ] 버튼
|
||||
val btnPrev = TextView(this).apply {
|
||||
text = " -0.5s "
|
||||
setTextColor(Color.YELLOW)
|
||||
setPadding(30, 10, 30, 10)
|
||||
setBackgroundColor(Color.parseColor("#66000000"))
|
||||
setOnClickListener {
|
||||
adjustSubtitleSync(500)
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// [ SYNC RESET ] 버튼
|
||||
val btnReset = TextView(this).apply {
|
||||
text = " SYNC RESET "
|
||||
setTextColor(Color.WHITE)
|
||||
setPadding(40, 10, 40, 10)
|
||||
setMargins(20, 0, 20, 0)
|
||||
setBackgroundColor(Color.parseColor("#AA000000"))
|
||||
setOnClickListener {
|
||||
syncSubtitleToCurrentTime()
|
||||
}
|
||||
}
|
||||
|
||||
// [ +0.5s ] 버튼
|
||||
val btnNext = TextView(this).apply {
|
||||
text = " +0.5s "
|
||||
setTextColor(Color.YELLOW)
|
||||
setPadding(30, 10, 30, 10)
|
||||
setBackgroundColor(Color.parseColor("#66000000"))
|
||||
setOnClickListener {
|
||||
adjustSubtitleSync(500)
|
||||
}
|
||||
}
|
||||
|
||||
topControlLayout.addView(btnPrev)
|
||||
topControlLayout.addView(btnReset)
|
||||
topControlLayout.addView(btnNext)
|
||||
|
||||
root.addView(topControlLayout, FrameLayout.LayoutParams(-2, -2, Gravity.TOP or Gravity.CENTER_HORIZONTAL).apply {
|
||||
topMargin = 100 // 노치나 상태바 아래로 배치
|
||||
})
|
||||
}
|
||||
|
||||
// 헬퍼 함수: Margin 적용용
|
||||
fun View.setMargins(l: Int, t: Int, r: Int, b: Int) {
|
||||
if (layoutParams is ViewGroup.MarginLayoutParams) {
|
||||
val p = layoutParams as ViewGroup.MarginLayoutParams
|
||||
p.setMargins(l, t, r, b)
|
||||
requestLayout()
|
||||
}
|
||||
}
|
||||
|
||||
private fun syncSubtitleToCurrentTime() {
|
||||
if (externalSubtitles.isEmpty()) return
|
||||
|
||||
val currentVideoSec = nativePlayer?.getCurrentPosition() ?: 0.0
|
||||
val firstSubtitleStartSec = externalSubtitles[0].startSec
|
||||
|
||||
val neededDelaySec = firstSubtitleStartSec - currentVideoSec
|
||||
subtitleDelayMs = (neededDelaySec * 1000).toLong()
|
||||
|
||||
currentSubtitleIndex = 0
|
||||
lastSubTitle = "" // 💡 추가: 즉시 갱신을 위해 비움
|
||||
|
||||
val sign = if (subtitleDelayMs >= 0) "+" else ""
|
||||
Toast.makeText(this, "자막 기준점 동기화 완료: $sign${String.format("%.1f", -neededDelaySec)}초 보정", Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
|
||||
private fun setupUI() {
|
||||
val root = FrameLayout(this).apply { setBackgroundColor(Color.BLACK) }
|
||||
@ -280,7 +355,7 @@ class PlayerActivity : AppCompatActivity(), TextureView.SurfaceTextureListener {
|
||||
root.addView(bottomControlLayout, FrameLayout.LayoutParams(-1, -2, Gravity.BOTTOM))
|
||||
root.addView(geckoWeb, FrameLayout.LayoutParams(-2, -2, Gravity.CENTER))
|
||||
setContentView(root)
|
||||
|
||||
setupSyncControls(root)
|
||||
hideSystemUI()
|
||||
}
|
||||
|
||||
@ -435,14 +510,15 @@ class PlayerActivity : AppCompatActivity(), TextureView.SurfaceTextureListener {
|
||||
private var subtitleDelayMs: Long = 0L
|
||||
private fun adjustSubtitleSync(deltaMs: Long) {
|
||||
subtitleDelayMs += deltaMs
|
||||
|
||||
// 💡 핵심: 기존 자막 상태를 초기화하여 루프가 즉시 새 자막을 그리도록 유도
|
||||
lastSubTitle = ""
|
||||
|
||||
val seconds = subtitleDelayMs / 1000.0
|
||||
val sign = if (subtitleDelayMs >= 0) "+" else ""
|
||||
Toast.makeText(this, "자막 싱크: $sign${String.format("%.1f", seconds)}초", Toast.LENGTH_SHORT).show()
|
||||
|
||||
// 싱크가 변경되면 즉시 루프에서 반영되므로 별도의 처리는 필요 없으나,
|
||||
// 즉각적인 피드백을 위해 lastSubTitle을 초기화하여 강제 갱신 유도 가능
|
||||
lastSubTitle = ""
|
||||
}
|
||||
|
||||
override fun onConfigurationChanged(newConfig: android.content.res.Configuration) {
|
||||
super.onConfigurationChanged(newConfig)
|
||||
hideSystemUI()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user