VideoView加上預設狀態

This commit is contained in:
Raymond Yang 2023-02-01 09:13:01 +08:00
parent c3f8366475
commit 90344d14b0

View File

@ -51,7 +51,7 @@ class VideoView : ConstraintLayout, SurfaceHolder.Callback, GstCallback {
private var retryRunnable = object : Runnable { private var retryRunnable = object : Runnable {
override fun run() { override fun run() {
play() play()
Log.e("${TAG}_$tag", "Retry count: $retryCount") //Log.e("${TAG}_$tag", "Retry count: $retryCount")
} }
} }
@ -73,12 +73,17 @@ class VideoView : ConstraintLayout, SurfaceHolder.Callback, GstCallback {
videoView.holder.addCallback(this) videoView.holder.addCallback(this)
gstLibrary = GstLibrary(context) gstLibrary = GstLibrary(context)
gstLibrary.setOnStatusChangeListener(this) gstLibrary.setOnStatusChangeListener(this)
view.textDeviceName.isVisible = false
isPlaying = false
isLoading = false
} }
fun setData(device: Device?) { fun setData(device: Device?) {
if (device == null) { if (device == null) {
view.textDeviceName.isVisible = false view.textDeviceName.isVisible = false
isPlaying = false isPlaying = false
isLoading = false
return return
} }
this.data = device this.data = device
@ -111,6 +116,9 @@ class VideoView : ConstraintLayout, SurfaceHolder.Callback, GstCallback {
override fun surfaceCreated(holder: SurfaceHolder) { override fun surfaceCreated(holder: SurfaceHolder) {
Log.d("${TAG}_$tag", "Surface created: " + holder.surface) Log.d("${TAG}_$tag", "Surface created: " + holder.surface)
if (this::gstLibrary.isInitialized) {
gstLibrary.setSurfaceHolder(holder)
}
} }
override fun surfaceChanged(holder: SurfaceHolder, format: Int, width: Int, height: Int) { override fun surfaceChanged(holder: SurfaceHolder, format: Int, width: Int, height: Int) {
@ -123,9 +131,9 @@ class VideoView : ConstraintLayout, SurfaceHolder.Callback, GstCallback {
override fun surfaceDestroyed(p0: SurfaceHolder) { override fun surfaceDestroyed(p0: SurfaceHolder) {
Log.d("${TAG}_$tag", "Surface destroyed") Log.d("${TAG}_$tag", "Surface destroyed")
// TODO: 如果呼叫 releaseSurface(),會閃退 // TODO: 如果呼叫 releaseSurface(),會閃退
/*if (this::gstLibrary.isInitialized) { if (this::gstLibrary.isInitialized) {
gstLibrary.releaseSurface() gstLibrary.releaseSurface()
}*/ }
} }
override fun onStatus(gstStatus: GstStatus?) { // onStatus 不是在主執行緒,因此透過 Handler 發訊息到主執行緒去執行 override fun onStatus(gstStatus: GstStatus?) { // onStatus 不是在主執行緒,因此透過 Handler 發訊息到主執行緒去執行
@ -137,11 +145,11 @@ class VideoView : ConstraintLayout, SurfaceHolder.Callback, GstCallback {
GstStatus.ERROR_WHEN_OPENING -> mHandler.sendMessage(Message().apply { what = MSG_ERROR }) GstStatus.ERROR_WHEN_OPENING -> mHandler.sendMessage(Message().apply { what = MSG_ERROR })
else -> {} else -> {}
} }
Log.e("${TAG}_$tag", "onStatus: $gstStatus") //Log.e("${TAG}_$tag", "onStatus: $gstStatus")
} }
override fun onMessage(message: String?) { override fun onMessage(message: String?) {
Log.e("${TAG}_$tag", "onMessage: $message") //Log.e("${TAG}_$tag", "onMessage: $message")
} }
inner class MyHandler(looper: Looper): Handler(looper) { inner class MyHandler(looper: Looper): Handler(looper) {
@ -166,7 +174,7 @@ class VideoView : ConstraintLayout, SurfaceHolder.Callback, GstCallback {
retryCount++ retryCount++
} else { } else {
retryCount = RETRY_OFF retryCount = RETRY_OFF
Log.e("${TAG}_$tag", "Retry count = 5, stopped retry...") //Log.e("${TAG}_$tag", "Retry count = 5, stopped retry...")
} }
} }
} }