將滑動控制加上播放/暫停
This commit is contained in:
parent
88954a6599
commit
ced178513b
@ -0,0 +1,5 @@
|
||||
package com.ray650128.gstreamer_demo_app
|
||||
|
||||
object Constants {
|
||||
const val CONF_DELAY_BASE_MILLIS = 300L
|
||||
}
|
||||
@ -8,6 +8,7 @@ import android.view.WindowManager
|
||||
import androidx.activity.viewModels
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.viewpager2.widget.ViewPager2
|
||||
import com.ray650128.gstreamer_demo_app.Constants
|
||||
import com.ray650128.gstreamer_demo_app.R
|
||||
import com.ray650128.gstreamer_demo_app.databinding.ActivityMainBinding
|
||||
import com.ray650128.gstreamer_demo_app.model.Device
|
||||
@ -55,6 +56,34 @@ class MainActivity : AppCompatActivity() {
|
||||
offscreenPageLimit = 1
|
||||
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", "onPageScrollStateChanged: ${
|
||||
when(state) {
|
||||
ViewPager2.SCROLL_STATE_IDLE -> "SCROLL_STATE_IDLE"
|
||||
ViewPager2.SCROLL_STATE_DRAGGING -> "SCROLL_STATE_DRAGGING"
|
||||
ViewPager2.SCROLL_STATE_SETTLING -> "SCROLL_STATE_SETTLING"
|
||||
else -> ""
|
||||
}
|
||||
}")
|
||||
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
|
||||
@ -102,7 +131,7 @@ class MainActivity : AppCompatActivity() {
|
||||
for (i in 0 until splitVideoViewAdapter.itemCount) {
|
||||
splitVideoViewAdapter.stop(i)
|
||||
}
|
||||
delay(oldSplitMode * 500L)
|
||||
delay(oldSplitMode * Constants.CONF_DELAY_BASE_MILLIS)
|
||||
oldSplitMode = splitMode
|
||||
splitVideoViewAdapter.clear()
|
||||
// 如果群組內沒有裝置,則顯示底圖
|
||||
@ -119,7 +148,7 @@ class MainActivity : AppCompatActivity() {
|
||||
splitVideoViewAdapter.add(i, splitFragment)
|
||||
}
|
||||
currentPage = 0
|
||||
binding.viewPager.currentItem = 0
|
||||
//binding.viewPager.currentItem = 0
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user