Hide video window when recording player has ended
This commit is contained in:
parent
78e66d4cf2
commit
c8a56c795b
4 changed files with 21 additions and 14 deletions
|
@ -26,7 +26,6 @@ import android.view.View
|
|||
import android.view.ViewGroup
|
||||
import androidx.databinding.DataBindingUtil
|
||||
import androidx.lifecycle.LifecycleOwner
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import androidx.recyclerview.widget.DiffUtil
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import org.linphone.R
|
||||
|
@ -41,9 +40,6 @@ class RecordingsListAdapter(
|
|||
selectionVM: ListTopBarViewModel,
|
||||
private val viewLifecycleOwner: LifecycleOwner
|
||||
) : SelectionListAdapter<RecordingData, RecyclerView.ViewHolder>(selectionVM, RecordingDiffCallback()), HeaderAdapter {
|
||||
val isVideoRecordingPlayingEvent: MutableLiveData<Event<Boolean>> by lazy {
|
||||
MutableLiveData<Event<Boolean>>()
|
||||
}
|
||||
|
||||
private lateinit var videoSurface: TextureView
|
||||
|
||||
|
@ -85,12 +81,10 @@ class RecordingsListAdapter(
|
|||
setPlayListener {
|
||||
if (recording.isPlaying.value == true) {
|
||||
recording.pause()
|
||||
isVideoRecordingPlayingEvent.value = Event(false)
|
||||
} else {
|
||||
recording.play()
|
||||
if (recording.isVideoAvailable()) {
|
||||
recording.setTextureView(videoSurface)
|
||||
isVideoRecordingPlayingEvent.value = Event(true)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,7 +35,7 @@ import org.linphone.core.PlayerListener
|
|||
import org.linphone.core.tools.Log
|
||||
import org.linphone.utils.LinphoneUtils
|
||||
|
||||
class RecordingData(val path: String) : Comparable<RecordingData> {
|
||||
class RecordingData(val path: String, private val recordingListener: RecordingListener) : Comparable<RecordingData> {
|
||||
companion object {
|
||||
val RECORD_PATTERN: Pattern =
|
||||
Pattern.compile(".*/(.*)_(\\d{2}-\\d{2}-\\d{4}-\\d{2}-\\d{2}-\\d{2})\\..*")
|
||||
|
@ -57,6 +57,7 @@ class RecordingData(val path: String) : Comparable<RecordingData> {
|
|||
private val listener = PlayerListener {
|
||||
Log.i("[Recording] End of file reached")
|
||||
stop()
|
||||
recordingListener.onPlayingEnded()
|
||||
}
|
||||
|
||||
private val textureViewListener = object : TextureView.SurfaceTextureListener {
|
||||
|
@ -118,6 +119,8 @@ class RecordingData(val path: String) : Comparable<RecordingData> {
|
|||
player.open(path)
|
||||
player.seek(0)
|
||||
}
|
||||
recordingListener.onPlayingStarted(isVideoAvailable())
|
||||
|
||||
player.start()
|
||||
isPlaying.value = true
|
||||
|
||||
|
@ -202,4 +205,9 @@ class RecordingData(val path: String) : Comparable<RecordingData> {
|
|||
private fun isClosed(): Boolean {
|
||||
return player.state == Player.State.Closed
|
||||
}
|
||||
|
||||
interface RecordingListener {
|
||||
fun onPlayingStarted(videoAvailable: Boolean)
|
||||
fun onPlayingEnded()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -98,12 +98,6 @@ class RecordingsFragment : MasterFragment<RecordingsFragmentBinding, RecordingsL
|
|||
true
|
||||
}
|
||||
|
||||
adapter.isVideoRecordingPlayingEvent.observe(viewLifecycleOwner, {
|
||||
it.consume { value ->
|
||||
viewModel.isVideoVisible.value = value
|
||||
}
|
||||
})
|
||||
|
||||
adapter.setVideoTextureView(binding.recordingVideoSurface)
|
||||
}
|
||||
|
||||
|
|
|
@ -31,6 +31,16 @@ class RecordingsViewModel : ViewModel() {
|
|||
|
||||
val isVideoVisible = MutableLiveData<Boolean>()
|
||||
|
||||
private val recordingListener = object : RecordingData.RecordingListener {
|
||||
override fun onPlayingStarted(videoAvailable: Boolean) {
|
||||
isVideoVisible.value = videoAvailable
|
||||
}
|
||||
|
||||
override fun onPlayingEnded() {
|
||||
isVideoVisible.value = false
|
||||
}
|
||||
}
|
||||
|
||||
init {
|
||||
getRecordings()
|
||||
isVideoVisible.value = false
|
||||
|
@ -57,7 +67,8 @@ class RecordingsViewModel : ViewModel() {
|
|||
if (RecordingData.RECORD_PATTERN.matcher(f.path).matches()) {
|
||||
list.add(
|
||||
RecordingData(
|
||||
f.path
|
||||
f.path,
|
||||
recordingListener
|
||||
)
|
||||
)
|
||||
Log.i("[Recordings] Found record ${f.path}")
|
||||
|
|
Loading…
Reference in a new issue