C lib加上tag區分
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
package com.ray650128.gstreamer_demo_app
|
||||
|
||||
object Constants {
|
||||
const val CONF_DELAY_BASE_MILLIS = 500L
|
||||
const val CONF_DELAY_BASE_MILLIS = 1000L
|
||||
}
|
||||
@@ -76,15 +76,15 @@ class MainActivity : AppCompatActivity() {
|
||||
if (state == ViewPager2.SCROLL_STATE_IDLE && currentPage == oldPage) {
|
||||
splitVideoViewAdapter.play(currentPage)
|
||||
}
|
||||
Log.d("Split", "onPageScrollStateChanged: ${
|
||||
/*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")
|
||||
}")*/
|
||||
//Log.d("Split", "oldPage: $oldPage, currentPage: $currentPage")
|
||||
}
|
||||
override fun onPageScrolled(
|
||||
position: Int,
|
||||
@@ -92,13 +92,13 @@ class MainActivity : AppCompatActivity() {
|
||||
positionOffsetPixels: Int
|
||||
) {
|
||||
super.onPageScrolled(position, positionOffset, positionOffsetPixels)
|
||||
Log.d("Split", "onPageScrolled: $currentPage")
|
||||
//Log.d("Split", "onPageScrolled: $currentPage")
|
||||
}
|
||||
override fun onPageSelected(position: Int) {
|
||||
super.onPageSelected(position)
|
||||
currentPage = position
|
||||
splitViewModel.activePage.postValue(position)
|
||||
Log.d("Split", "currentPage: $currentPage")
|
||||
//Log.d("Split", "currentPage: $currentPage")
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -10,15 +10,6 @@ class MainViewModel: ViewModel() {
|
||||
|
||||
private val uriList: List<Device> by lazy {
|
||||
listOf(
|
||||
Device(
|
||||
deviceName = "192.168.0.73",
|
||||
ip = "192.168.0.73",
|
||||
rtspPort = "554",
|
||||
account = "admin",
|
||||
password = "hs22601576",
|
||||
stream1 = "/media/video1",
|
||||
stream2 = "/media/video2",
|
||||
),
|
||||
Device(
|
||||
deviceName = "192.168.0.77",
|
||||
ip = "192.168.0.77",
|
||||
@@ -28,6 +19,15 @@ class MainViewModel: ViewModel() {
|
||||
stream1 = "/media/video1",
|
||||
stream2 = "/media/video2",
|
||||
),
|
||||
Device(
|
||||
deviceName = "192.168.0.73",
|
||||
ip = "192.168.0.73",
|
||||
rtspPort = "554",
|
||||
account = "admin",
|
||||
password = "hs22601576",
|
||||
stream1 = "/media/video1",
|
||||
stream2 = "/media/video2",
|
||||
),
|
||||
Device(
|
||||
deviceName = "192.168.0.79",
|
||||
ip = "192.168.0.79",
|
||||
|
||||
@@ -18,7 +18,7 @@ import com.ray650128.gstreamer_demo_app.databinding.ItemVideoViewBinding
|
||||
import com.ray650128.gstreamer_demo_app.extensions.getStreamPath
|
||||
import com.ray650128.gstreamer_demo_app.model.Device
|
||||
|
||||
class VideoView : ConstraintLayout, SurfaceHolder.Callback, GstCallback {
|
||||
class VideoView : ConstraintLayout, GstCallback {
|
||||
|
||||
constructor(context: Context) : super(context) {
|
||||
initView(context)
|
||||
@@ -69,8 +69,9 @@ class VideoView : ConstraintLayout, SurfaceHolder.Callback, GstCallback {
|
||||
view = ItemVideoViewBinding.inflate(layoutInflater, this, true)
|
||||
view.baseView.clipToOutline = true
|
||||
|
||||
videoView.holder.addCallback(this)
|
||||
//videoView.holder.addCallback(this)
|
||||
gstLibrary = GstLibrary(context)
|
||||
gstLibrary.setSurfaceHolder(videoView.holder)
|
||||
gstLibrary.setOnStatusChangeListener(this)
|
||||
|
||||
// View 預設狀態
|
||||
@@ -91,6 +92,7 @@ class VideoView : ConstraintLayout, SurfaceHolder.Callback, GstCallback {
|
||||
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")
|
||||
}
|
||||
@@ -100,11 +102,13 @@ class VideoView : ConstraintLayout, SurfaceHolder.Callback, GstCallback {
|
||||
}
|
||||
|
||||
fun play() {
|
||||
if (data == null) return
|
||||
videoView.postInvalidate()
|
||||
gstLibrary.play()
|
||||
}
|
||||
|
||||
fun stop() {
|
||||
if (data == null) return
|
||||
isPlaying = false
|
||||
if (this::gstLibrary.isInitialized) {
|
||||
gstLibrary.stop()
|
||||
@@ -126,27 +130,6 @@ class VideoView : ConstraintLayout, SurfaceHolder.Callback, GstCallback {
|
||||
mHandler.removeCallbacks(retryRunnable)
|
||||
}
|
||||
|
||||
override fun surfaceCreated(holder: SurfaceHolder) {
|
||||
Log.d("${TAG}_$tag", "Surface created: " + holder.surface)
|
||||
if (this::gstLibrary.isInitialized) {
|
||||
gstLibrary.setSurfaceHolder(holder)
|
||||
}
|
||||
}
|
||||
|
||||
override fun surfaceChanged(holder: SurfaceHolder, format: Int, width: Int, height: Int) {
|
||||
Log.d("${TAG}_$tag", "Surface changed, format: $format, width: $width, height: $height")
|
||||
/*if (this::gstLibrary.isInitialized) {
|
||||
gstLibrary.setSurfaceHolder(holder)
|
||||
}*/
|
||||
}
|
||||
|
||||
override fun surfaceDestroyed(p0: SurfaceHolder) {
|
||||
Log.d("${TAG}_$tag", "Surface destroyed")
|
||||
if (this::gstLibrary.isInitialized) {
|
||||
gstLibrary.releaseSurface()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onStatus(gstStatus: GstStatus?) { // onStatus 不是在主執行緒,因此透過 Handler 發訊息到主執行緒去執行
|
||||
when (gstStatus) {
|
||||
GstStatus.PLAYING -> mHandler.sendMessage(Message().apply { what = MSG_PLAY })
|
||||
|
||||
Reference in New Issue
Block a user