在surfaceDestroyed裡面呼叫pause
This commit is contained in:
parent
975e2eba79
commit
c9ca4156aa
@ -68,26 +68,6 @@ class MainActivity : AppCompatActivity() {
|
||||
offscreenPageLimit = 100
|
||||
setPageTransformer(null)
|
||||
registerOnPageChangeCallback(object: ViewPager2.OnPageChangeCallback() {
|
||||
private var oldPage = 0
|
||||
override fun onPageScrollStateChanged(state: Int) {
|
||||
super.onPageScrollStateChanged(state)
|
||||
/*if (state == ViewPager2.SCROLL_STATE_DRAGGING) {
|
||||
oldPage = currentPage
|
||||
splitVideoViewAdapter.stop(currentPage)
|
||||
}
|
||||
if (state == ViewPager2.SCROLL_STATE_IDLE && currentPage == oldPage) {
|
||||
splitVideoViewAdapter.play(currentPage)
|
||||
}*/
|
||||
//Log.d("Split", "oldPage: $oldPage, currentPage: $currentPage")
|
||||
}
|
||||
override fun onPageScrolled(
|
||||
position: Int,
|
||||
positionOffset: Float,
|
||||
positionOffsetPixels: Int
|
||||
) {
|
||||
super.onPageScrolled(position, positionOffset, positionOffsetPixels)
|
||||
//Log.d("Split", "onPageScrolled: $currentPage")
|
||||
}
|
||||
override fun onPageSelected(position: Int) {
|
||||
super.onPageSelected(position)
|
||||
currentPage = position
|
||||
@ -133,7 +113,7 @@ class MainActivity : AppCompatActivity() {
|
||||
private fun reloadVideoViews(list: List<List<Device>>?) = MainScope().launch {
|
||||
binding.viewPager.setCurrentItem(0, false)
|
||||
for (i in 0 until splitVideoViewAdapter.itemCount) {
|
||||
splitVideoViewAdapter.stop(i)
|
||||
splitVideoViewAdapter.pause(i)
|
||||
}
|
||||
//delay(oldSplitMode * Constants.CONF_DELAY_BASE_MILLIS)
|
||||
delay((oldSplitMode * 100) + Constants.CONF_DELAY_BASE_MILLIS)
|
||||
|
||||
@ -206,7 +206,7 @@ class SplitViewFragment : Fragment() {
|
||||
for (index in data.indices) {
|
||||
videoViews[index].stopRetryCount()
|
||||
if (!videoViews[index].isPlaying || videoViews[index].isLoading) continue
|
||||
videoViews[index].stop()
|
||||
videoViews[index].pause()
|
||||
//delay(300)
|
||||
}
|
||||
}.start()
|
||||
|
||||
@ -109,11 +109,11 @@ class VideoView : ConstraintLayout, GstCallback {
|
||||
gstLibrary.play()
|
||||
}
|
||||
|
||||
fun stop() {
|
||||
fun pause() {
|
||||
if (data == null) return
|
||||
isPlaying = false
|
||||
if (this::gstLibrary.isInitialized) {
|
||||
gstLibrary.stop()
|
||||
gstLibrary.pause()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -41,11 +41,11 @@ class VideoViewAdapter(
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
|
||||
fun stop(index: Int) {
|
||||
stop(fragments[index])
|
||||
fun pause(index: Int) {
|
||||
pause(fragments[index])
|
||||
}
|
||||
|
||||
private fun stop(fragment: SplitViewFragment) {
|
||||
private fun pause(fragment: SplitViewFragment) {
|
||||
fragment.stopAll()
|
||||
}
|
||||
|
||||
|
||||
@ -31,7 +31,7 @@ class GstLibrary(context: Context) : Closeable, SurfaceHolder.Callback {
|
||||
nativePlay()
|
||||
}
|
||||
|
||||
fun stop() {
|
||||
fun pause() {
|
||||
if (!isInit) return
|
||||
nativePause()
|
||||
}
|
||||
@ -139,6 +139,7 @@ class GstLibrary(context: Context) : Closeable, SurfaceHolder.Callback {
|
||||
|
||||
override fun surfaceDestroyed(holder: SurfaceHolder) {
|
||||
Log.d("$TAG+$tag", "Surface destroyed")
|
||||
pause()
|
||||
releaseSurface()
|
||||
isInit = false
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user