當MainActivity退出時,呼叫GStreamer的finalize
This commit is contained in:
parent
53763bfa34
commit
dc1da2449b
@ -47,6 +47,16 @@ class MainActivity : AppCompatActivity() {
|
||||
initObservers()
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
super.onDestroy()
|
||||
MainScope().launch {
|
||||
for (i in 0 until splitVideoViewAdapter.itemCount) {
|
||||
splitVideoViewAdapter.destroy(i)
|
||||
//delay(100)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun initContentView() = binding.apply {
|
||||
//region Content area
|
||||
splitVideoViewAdapter = VideoViewAdapter(supportFragmentManager, lifecycle)
|
||||
|
||||
@ -84,6 +84,12 @@ class SplitViewFragment : Fragment() {
|
||||
Log.d("${TAG}_$mPageNum", "onResume()")
|
||||
}
|
||||
|
||||
/*override fun onDestroy() {
|
||||
super.onDestroy()
|
||||
destroyAll()
|
||||
Log.d("${TAG}_$mPageNum", "onDestroy()")
|
||||
}*/
|
||||
|
||||
private fun initView() {
|
||||
// 生成 VideoView 分割畫面
|
||||
binding.apply {
|
||||
@ -203,6 +209,14 @@ class SplitViewFragment : Fragment() {
|
||||
}
|
||||
}.start()
|
||||
|
||||
fun destroyAll() = MainScope().launch(Dispatchers.Main) {
|
||||
if (videoViews.isEmpty()) return@launch
|
||||
for (index in data.indices) {
|
||||
videoViews[index].destroy()
|
||||
delay(100)
|
||||
}
|
||||
}.start()
|
||||
|
||||
companion object {
|
||||
private val TAG = SplitViewFragment::class.java.simpleName
|
||||
private const val ARG_PAGE_NUM = "page_number"
|
||||
|
||||
@ -111,6 +111,12 @@ class VideoView : ConstraintLayout, SurfaceHolder.Callback, GstCallback {
|
||||
}
|
||||
}
|
||||
|
||||
fun destroy() {
|
||||
if (this::gstLibrary.isInitialized) {
|
||||
gstLibrary.close()
|
||||
}
|
||||
}
|
||||
|
||||
fun resetRetryCount() {
|
||||
retryCount = 0
|
||||
}
|
||||
|
||||
@ -57,6 +57,14 @@ class VideoViewAdapter(
|
||||
fragment.playAll()
|
||||
}
|
||||
|
||||
fun destroy(index: Int) {
|
||||
destroy(fragments[index])
|
||||
}
|
||||
|
||||
private fun destroy(fragment: SplitViewFragment) {
|
||||
fragment.destroyAll()
|
||||
}
|
||||
|
||||
override fun getItemId(position: Int): Long {
|
||||
return fragments[position].hashCode().toLong()
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user