加入TextureView支援
This commit is contained in:
+8
-11
@@ -22,8 +22,6 @@ import kotlin.math.sqrt
|
||||
|
||||
class SplitViewFragment : Fragment() {
|
||||
|
||||
val viewModel: SplitViewModel by activityViewModels()
|
||||
|
||||
private var mPageNum: Int = 0
|
||||
private var splitMode = Constants.SPLIT_MODE_SINGLE
|
||||
private var streamType = VideoView.SUB_STREAM
|
||||
@@ -213,32 +211,31 @@ class SplitViewFragment : Fragment() {
|
||||
|
||||
fun playAll() = MainScope().launch(Dispatchers.Main) {
|
||||
if (videoViews.isEmpty()) return@launch
|
||||
delay(splitMode * Constants.CONF_DELAY_BASE_MILLIS)
|
||||
//delay(splitMode * Constants.CONF_DELAY_BASE_MILLIS)
|
||||
for (index in data.indices) {
|
||||
if (!videoViews[index].isReady) continue
|
||||
videoViews[index].resetRetryCount()
|
||||
videoViews[index].play()
|
||||
//delay(300)
|
||||
delay(300)
|
||||
}
|
||||
}.start()
|
||||
|
||||
fun stopAll() = MainScope().launch(Dispatchers.Main) {
|
||||
if (videoViews.isEmpty()) return@launch
|
||||
fun stopAll() {
|
||||
if (videoViews.isEmpty()) return
|
||||
for (index in data.indices) {
|
||||
videoViews[index].stopRetryCount()
|
||||
if (!videoViews[index].isPlaying || videoViews[index].isLoading) continue
|
||||
videoViews[index].pause()
|
||||
//delay(300)
|
||||
}
|
||||
}.start()
|
||||
}
|
||||
|
||||
fun destroyAll() = MainScope().launch(Dispatchers.Main) {
|
||||
if (videoViews.isEmpty()) return@launch
|
||||
fun destroyAll() {
|
||||
if (videoViews.isEmpty()) return
|
||||
for (index in data.indices) {
|
||||
//videoViews[index].destroy()
|
||||
videoViews[index].destroySurface()
|
||||
}
|
||||
}.start()
|
||||
}
|
||||
|
||||
companion object {
|
||||
private val TAG = SplitViewFragment::class.java.simpleName
|
||||
|
||||
@@ -9,6 +9,7 @@ import android.util.Log
|
||||
import android.view.LayoutInflater
|
||||
import android.view.SurfaceHolder
|
||||
import android.view.SurfaceView
|
||||
import android.view.TextureView
|
||||
import androidx.constraintlayout.widget.ConstraintLayout
|
||||
import androidx.core.view.isVisible
|
||||
import com.hisharp.gstreamer_player.GstCallback
|
||||
@@ -62,7 +63,7 @@ class VideoView : ConstraintLayout, GstCallback {
|
||||
}
|
||||
}
|
||||
|
||||
private val videoView: SurfaceView by lazy { view.videoView }
|
||||
private val videoView: TextureView by lazy { view.videoView }
|
||||
|
||||
private lateinit var gstLibrary: GstLibrary
|
||||
|
||||
@@ -77,7 +78,8 @@ class VideoView : ConstraintLayout, GstCallback {
|
||||
|
||||
//videoView.holder.addCallback(this)
|
||||
gstLibrary = GstLibrary(context)
|
||||
gstLibrary.setSurfaceHolder(videoView.holder)
|
||||
//gstLibrary.setSurfaceHolder(videoView.holder)
|
||||
gstLibrary.setTextureView(videoView)
|
||||
gstLibrary.setOnStatusChangeListener(this)
|
||||
|
||||
// View 預設狀態
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
android:background="@drawable/bg_video_view"
|
||||
android:outlineProvider="background">
|
||||
|
||||
<SurfaceView
|
||||
<TextureView
|
||||
android:id="@+id/videoView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
|
||||
Reference in New Issue
Block a user