1.優化for loop
2.優化VideoView get/set
This commit is contained in:
parent
8449706b64
commit
ba12fd3856
@ -162,14 +162,13 @@ class SplitViewFragment : Fragment() {
|
||||
}
|
||||
|
||||
if (isClickable) {
|
||||
for (position in videoViews.indices) {
|
||||
videoViews[position].setOnClickListener {
|
||||
if (position >= data.size) return@setOnClickListener
|
||||
/*if (!videoViews[position].isPlaying) {
|
||||
videoViews.forEach { videoView ->
|
||||
videoView.setOnClickListener {
|
||||
if (!videoView.isPlaying) {
|
||||
return@setOnClickListener
|
||||
}*/
|
||||
}
|
||||
stopAll()
|
||||
val item = data[position]
|
||||
val item = videoView.data
|
||||
val bundle = Bundle().apply {
|
||||
//putInt(MonitoringActivity.BUNDLE_DEVICE_ID, item.id)
|
||||
//putInt(MonitoringActivity.BUNDLE_CHANNEL_ID, item.channelId)
|
||||
@ -189,27 +188,23 @@ class SplitViewFragment : Fragment() {
|
||||
|
||||
private fun setAllUrl() {
|
||||
for (index in data.indices) {
|
||||
videoViews[index].setData(data[index])
|
||||
videoViews[index].data = data[index]
|
||||
videoViews[index].setTextVisible(
|
||||
(splitMode != Constants.SPLIT_MODE_NINE && splitMode != Constants.SPLIT_MODE_SIXTEEN)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
fun playAll() = MainScope().launch(Dispatchers.Main) {
|
||||
if (videoViews.isEmpty()) return@launch
|
||||
delay(splitMode * Constants.CONF_DELAY_BASE_MILLIS)
|
||||
fun playAll() {
|
||||
videoViews.forEach { videoView ->
|
||||
if (videoView.isReady) {
|
||||
videoView.resetRetryCount()
|
||||
videoView.play()
|
||||
//delay(300)
|
||||
}
|
||||
}
|
||||
}.start()
|
||||
}
|
||||
|
||||
fun stopAll() {
|
||||
if (videoViews.isEmpty()) return
|
||||
videoViews.forEach { videoView ->
|
||||
videoView.stopRetryCount()
|
||||
if (videoView.isPlaying || !videoView.isLoading) {
|
||||
@ -219,7 +214,6 @@ class SplitViewFragment : Fragment() {
|
||||
}
|
||||
|
||||
fun destroyAll() {
|
||||
if (videoViews.isEmpty()) return
|
||||
videoViews.forEach { videoView ->
|
||||
//videoView.destroy()
|
||||
videoView.destroySurface()
|
||||
|
||||
@ -35,7 +35,25 @@ class VideoView : ConstraintLayout, GstCallback {
|
||||
|
||||
private lateinit var view: ItemVideoViewBinding
|
||||
|
||||
private var data: Device? = null
|
||||
var streamType: Int = MAIN_STREAM
|
||||
|
||||
var data: Device? = null
|
||||
set(value) {
|
||||
field = value
|
||||
if (field == null) {
|
||||
view.textDeviceName.isVisible = false
|
||||
isPlaying = false
|
||||
isLoading = false
|
||||
return
|
||||
}
|
||||
this.tag = field?.deviceName
|
||||
view.textDeviceName.text = field?.deviceName
|
||||
view.textDeviceName.isVisible = true
|
||||
val rtspUrl = this.data?.getStreamPath(streamType) ?: return // 如果 null 就不指派給 Gstreamer 了
|
||||
gstLibrary.setTag(this.data!!.deviceName)
|
||||
gstLibrary.setRtspUrl(rtspUrl)
|
||||
Log.d("${TAG}_$tag", "Set device to: $field, rtspUrl = $rtspUrl")
|
||||
}
|
||||
|
||||
var isReady: Boolean = false
|
||||
|
||||
@ -95,23 +113,6 @@ class VideoView : ConstraintLayout, GstCallback {
|
||||
}
|
||||
}
|
||||
|
||||
fun setData(device: Device?, streamType: Int = SUB_STREAM) {
|
||||
if (device == null) {
|
||||
view.textDeviceName.isVisible = false
|
||||
isPlaying = false
|
||||
isLoading = false
|
||||
return
|
||||
}
|
||||
this.data = device
|
||||
this.tag = device.deviceName
|
||||
view.textDeviceName.text = device.deviceName
|
||||
view.textDeviceName.isVisible = true
|
||||
val rtspUrl = this.data?.getStreamPath(streamType) ?: return // 如果 null 就不指派給 Gstreamer 了
|
||||
gstLibrary.setTag(this.data!!.deviceName)
|
||||
gstLibrary.setRtspUrl(rtspUrl)
|
||||
Log.d("${TAG}_$tag", "Set device to: $device, rtspUrl = $rtspUrl")
|
||||
}
|
||||
|
||||
fun setTextVisible(isVisible: Boolean) {
|
||||
view.textDeviceName.isVisible = isVisible
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user