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