VideoViewAdapter.kt加上對所有的SplitViewFragment.kt下指令的功能

This commit is contained in:
Raymond Yang 2023-03-09 15:02:27 +08:00
parent 0ffafcbaf7
commit f7aa9f74d2
3 changed files with 19 additions and 8 deletions

View File

@ -53,9 +53,7 @@ class MainActivity : AppCompatActivity() {
} }
override fun onDestroy() { override fun onDestroy() {
for (i in 0 until splitVideoViewAdapter.itemCount) { splitVideoViewAdapter.destroy()
splitVideoViewAdapter.destroy(i)
}
super.onDestroy() super.onDestroy()
} }
@ -113,8 +111,8 @@ class MainActivity : AppCompatActivity() {
private fun reloadVideoViews(list: List<List<Device>>?) = MainScope().launch { private fun reloadVideoViews(list: List<List<Device>>?) = MainScope().launch {
binding.viewPager.setCurrentItem(0, false) binding.viewPager.setCurrentItem(0, false)
for (i in 0 until splitVideoViewAdapter.itemCount) { for (i in 0 until splitVideoViewAdapter.itemCount) {
splitVideoViewAdapter.pause(i) splitVideoViewAdapter.pause()
splitVideoViewAdapter.destroy(i) splitVideoViewAdapter.destroy()
} }
//delay(oldSplitMode * Constants.CONF_DELAY_BASE_MILLIS) //delay(oldSplitMode * Constants.CONF_DELAY_BASE_MILLIS)
delay((oldSplitMode * 100) + Constants.CONF_DELAY_BASE_MILLIS) delay((oldSplitMode * 100) + Constants.CONF_DELAY_BASE_MILLIS)

View File

@ -162,6 +162,7 @@ class SplitViewFragment : Fragment() {
} }
MainScope().launch { MainScope().launch {
stopAll() stopAll()
//delay(Constants.CONF_DELAY_BASE_MILLIS)
delay(splitMode * Constants.CONF_DELAY_BASE_MILLIS) delay(splitMode * Constants.CONF_DELAY_BASE_MILLIS)
//delay((splitMode * 100) + Constants.CONF_DELAY_BASE_MILLIS) //delay((splitMode * 100) + Constants.CONF_DELAY_BASE_MILLIS)
val item = data[position] val item = data[position]
@ -211,13 +212,13 @@ class SplitViewFragment : Fragment() {
} }
}.start() }.start()
fun destroyAll() /*= MainScope().launch(Dispatchers.Main)*/ { fun destroyAll() = MainScope().launch(Dispatchers.Main) {
if (videoViews.isEmpty()) return if (videoViews.isEmpty()) return@launch
for (index in data.indices) { for (index in data.indices) {
//videoViews[index].destroy() //videoViews[index].destroy()
videoViews[index].destroySurface() videoViews[index].destroySurface()
} }
}//.start() }.start()
companion object { companion object {
private val TAG = SplitViewFragment::class.java.simpleName private val TAG = SplitViewFragment::class.java.simpleName

View File

@ -41,6 +41,12 @@ class VideoViewAdapter(
notifyDataSetChanged() notifyDataSetChanged()
} }
fun pause() {
for (i in fragments.indices) {
pause(i)
}
}
fun pause(index: Int) { fun pause(index: Int) {
pause(fragments[index]) pause(fragments[index])
} }
@ -57,6 +63,12 @@ class VideoViewAdapter(
fragment.playAll() fragment.playAll()
} }
fun destroy() {
for (i in fragments.indices) {
destroy(i)
}
}
fun destroy(index: Int) { fun destroy(index: Int) {
destroy(fragments[index]) destroy(fragments[index])
} }