當MainActivity退出時,呼叫GStreamer的finalize
This commit is contained in:
parent
53763bfa34
commit
dc1da2449b
@ -47,6 +47,16 @@ class MainActivity : AppCompatActivity() {
|
|||||||
initObservers()
|
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 {
|
private fun initContentView() = binding.apply {
|
||||||
//region Content area
|
//region Content area
|
||||||
splitVideoViewAdapter = VideoViewAdapter(supportFragmentManager, lifecycle)
|
splitVideoViewAdapter = VideoViewAdapter(supportFragmentManager, lifecycle)
|
||||||
|
|||||||
@ -84,6 +84,12 @@ class SplitViewFragment : Fragment() {
|
|||||||
Log.d("${TAG}_$mPageNum", "onResume()")
|
Log.d("${TAG}_$mPageNum", "onResume()")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*override fun onDestroy() {
|
||||||
|
super.onDestroy()
|
||||||
|
destroyAll()
|
||||||
|
Log.d("${TAG}_$mPageNum", "onDestroy()")
|
||||||
|
}*/
|
||||||
|
|
||||||
private fun initView() {
|
private fun initView() {
|
||||||
// 生成 VideoView 分割畫面
|
// 生成 VideoView 分割畫面
|
||||||
binding.apply {
|
binding.apply {
|
||||||
@ -203,6 +209,14 @@ class SplitViewFragment : Fragment() {
|
|||||||
}
|
}
|
||||||
}.start()
|
}.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 {
|
companion object {
|
||||||
private val TAG = SplitViewFragment::class.java.simpleName
|
private val TAG = SplitViewFragment::class.java.simpleName
|
||||||
private const val ARG_PAGE_NUM = "page_number"
|
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() {
|
fun resetRetryCount() {
|
||||||
retryCount = 0
|
retryCount = 0
|
||||||
}
|
}
|
||||||
|
|||||||
@ -57,6 +57,14 @@ class VideoViewAdapter(
|
|||||||
fragment.playAll()
|
fragment.playAll()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun destroy(index: Int) {
|
||||||
|
destroy(fragments[index])
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun destroy(fragment: SplitViewFragment) {
|
||||||
|
fragment.destroyAll()
|
||||||
|
}
|
||||||
|
|
||||||
override fun getItemId(position: Int): Long {
|
override fun getItemId(position: Int): Long {
|
||||||
return fragments[position].hashCode().toLong()
|
return fragments[position].hashCode().toLong()
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user