清理程式碼,並加上註解
This commit is contained in:
parent
eb4f643e99
commit
642d0e7525
@ -89,6 +89,7 @@ class MainActivity : AppCompatActivity() {
|
||||
}
|
||||
|
||||
private fun reloadVideoViews(list: List<List<Device>>?) = MainScope().launch {
|
||||
binding.viewPager.setCurrentItem(0, false)
|
||||
splitVideoViewAdapter.clear()
|
||||
// 如果群組內沒有裝置,則顯示底圖
|
||||
if (list.isNullOrEmpty()) {
|
||||
|
||||
@ -129,7 +129,6 @@ class SplitViewFragment : Fragment() {
|
||||
for (position in videoViews.indices) {
|
||||
videoViews[position].setOnClickListener {
|
||||
if (position >= data.size) return@setOnClickListener
|
||||
videoViews[position].play()
|
||||
/*if (!videoViews[position].isPlaying) {
|
||||
if (!videoViews[position].isLoading) {
|
||||
videoViews[position].play()
|
||||
@ -164,13 +163,10 @@ class SplitViewFragment : Fragment() {
|
||||
}
|
||||
}
|
||||
|
||||
fun stopAll() {
|
||||
fun stopAll() = MainScope().launch(Dispatchers.Main) {
|
||||
for (index in data.indices) {
|
||||
try {
|
||||
videoViews[index].stop()
|
||||
} catch (e: IllegalStateException) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
videoViews[index].stop()
|
||||
delay(300)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -72,6 +72,7 @@ class VideoView : ConstraintLayout, SurfaceHolder.Callback, GstCallback {
|
||||
fun setData(device: Device?) {
|
||||
if (device == null) {
|
||||
view.textDeviceName.isVisible = false
|
||||
isPlaying = false
|
||||
return
|
||||
}
|
||||
this.data = device
|
||||
@ -86,24 +87,16 @@ class VideoView : ConstraintLayout, SurfaceHolder.Callback, GstCallback {
|
||||
view.textDeviceName.isVisible = isVisible
|
||||
}
|
||||
|
||||
fun setViewSize(width: Int, height: Int) {
|
||||
layoutParams?.width = width
|
||||
layoutParams?.height = height
|
||||
}
|
||||
|
||||
fun play() {
|
||||
//videoView.isVisible = true
|
||||
videoView.postInvalidate()
|
||||
gstLibrary.play()
|
||||
retryCount = 0
|
||||
}
|
||||
|
||||
fun stop() {
|
||||
//videoView.isVisible = false
|
||||
isPlaying = false
|
||||
if (this::gstLibrary.isInitialized) {
|
||||
gstLibrary.stop()
|
||||
//gstLibrary.releaseSurface()
|
||||
}
|
||||
retryCount = 999
|
||||
}
|
||||
@ -121,27 +114,17 @@ class VideoView : ConstraintLayout, SurfaceHolder.Callback, GstCallback {
|
||||
|
||||
override fun surfaceDestroyed(p0: SurfaceHolder) {
|
||||
Log.d("${TAG}_$tag", "Surface destroyed")
|
||||
// TODO: 如果呼叫 releaseSurface(),會閃退
|
||||
/*if (this::gstLibrary.isInitialized) {
|
||||
gstLibrary.releaseSurface()
|
||||
}*/
|
||||
}
|
||||
|
||||
override fun onStatus(gstStatus: GstStatus?) {
|
||||
override fun onStatus(gstStatus: GstStatus?) { // onStatus 不是在主執行緒,因此透過 Handler 發訊息到主執行緒去執行
|
||||
when (gstStatus) {
|
||||
GstStatus.PLAYING -> {
|
||||
mHandler.sendMessage(
|
||||
Message().apply {
|
||||
what = MSG_PLAY
|
||||
}
|
||||
)
|
||||
}
|
||||
GstStatus.PAUSE -> {
|
||||
mHandler.sendMessage(
|
||||
Message().apply {
|
||||
what = MSG_PAUSE
|
||||
}
|
||||
)
|
||||
}
|
||||
GstStatus.PLAYING -> mHandler.sendMessage(Message().apply { what = MSG_PLAY })
|
||||
GstStatus.PAUSE -> mHandler.sendMessage(Message().apply { what = MSG_PAUSE })
|
||||
GstStatus.ERROR_WHEN_OPENING -> mHandler.sendMessage(Message().apply { what = MSG_PAUSE })
|
||||
else -> {}
|
||||
}
|
||||
Log.e("${TAG}_$tag", "onStatus: $gstStatus")
|
||||
@ -153,7 +136,6 @@ class VideoView : ConstraintLayout, SurfaceHolder.Callback, GstCallback {
|
||||
|
||||
inner class MyHandler(looper: Looper): Handler(looper) {
|
||||
override fun handleMessage(msg: Message) {
|
||||
//super.handleMessage(msg)
|
||||
when(msg.what) {
|
||||
MSG_PAUSE -> {
|
||||
isPlaying = false
|
||||
|
||||
Loading…
Reference in New Issue
Block a user