mirror of
https://github.com/Novaloop-AG/element-x-android.git
synced 2026-10-31 16:22:49 +00:00
Show voice message preview player progress (#1675)
* Show voice message preview player progress * Update screenshots * Fix test * Some nits over mediaplayer stuff --------- Co-authored-by: ElementBot <benoitm+elementbot@element.io> Co-authored-by: Marco Romano <marcor@element.io>
This commit is contained in:
+4
@@ -74,5 +74,9 @@ interface MediaPlayer : AutoCloseable {
|
||||
* The current position of the player.
|
||||
*/
|
||||
val currentPosition: Long,
|
||||
/**
|
||||
* The duration of the current content.
|
||||
*/
|
||||
val duration: Long,
|
||||
)
|
||||
}
|
||||
|
||||
+3
-1
@@ -47,6 +47,7 @@ class MediaPlayerImpl @Inject constructor(
|
||||
_state.update {
|
||||
it.copy(
|
||||
currentPosition = player.currentPosition,
|
||||
duration = player.duration.coerceAtLeast(0),
|
||||
isPlaying = isPlaying,
|
||||
)
|
||||
}
|
||||
@@ -61,6 +62,7 @@ class MediaPlayerImpl @Inject constructor(
|
||||
_state.update {
|
||||
it.copy(
|
||||
currentPosition = player.currentPosition,
|
||||
duration = player.duration.coerceAtLeast(0),
|
||||
mediaId = mediaItem?.mediaId,
|
||||
)
|
||||
}
|
||||
@@ -74,7 +76,7 @@ class MediaPlayerImpl @Inject constructor(
|
||||
private val scope = CoroutineScope(Job() + Dispatchers.Main)
|
||||
private var job: Job? = null
|
||||
|
||||
private val _state = MutableStateFlow(MediaPlayer.State(false, null, 0L))
|
||||
private val _state = MutableStateFlow(MediaPlayer.State(false, null, 0L, 0L))
|
||||
|
||||
override val state: StateFlow<MediaPlayer.State> = _state.asStateFlow()
|
||||
|
||||
|
||||
+3
@@ -33,6 +33,7 @@ interface SimplePlayer {
|
||||
fun addListener(listener: Listener)
|
||||
val currentPosition: Long
|
||||
val playbackState: Int
|
||||
val duration: Long
|
||||
fun clearMediaItems()
|
||||
fun setMediaItem(mediaItem: MediaItem)
|
||||
fun getCurrentMediaItem(): MediaItem?
|
||||
@@ -73,6 +74,8 @@ class SimplePlayerImpl(
|
||||
get() = p.currentPosition
|
||||
override val playbackState: Int
|
||||
get() = p.playbackState
|
||||
override val duration: Long
|
||||
get() = p.duration
|
||||
|
||||
override fun clearMediaItems() = p.clearMediaItems()
|
||||
|
||||
|
||||
+10
-3
@@ -26,7 +26,12 @@ import kotlinx.coroutines.flow.update
|
||||
* Fake implementation of [MediaPlayer] for testing purposes.
|
||||
*/
|
||||
class FakeMediaPlayer : MediaPlayer {
|
||||
private val _state = MutableStateFlow(MediaPlayer.State(false, null, 0L))
|
||||
companion object {
|
||||
private const val FAKE_TOTAL_DURATION_MS = 10_000L
|
||||
private const val FAKE_PLAYED_DURATION_MS = 1000L
|
||||
}
|
||||
|
||||
private val _state = MutableStateFlow(MediaPlayer.State(false, null, 0L, 0L))
|
||||
|
||||
override val state: StateFlow<MediaPlayer.State> = _state.asStateFlow()
|
||||
|
||||
@@ -35,7 +40,8 @@ class FakeMediaPlayer : MediaPlayer {
|
||||
it.copy(
|
||||
isPlaying = true,
|
||||
mediaId = mediaId,
|
||||
currentPosition = it.currentPosition + 1000L,
|
||||
currentPosition = it.currentPosition + FAKE_PLAYED_DURATION_MS,
|
||||
duration = FAKE_TOTAL_DURATION_MS,
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -44,7 +50,8 @@ class FakeMediaPlayer : MediaPlayer {
|
||||
_state.update {
|
||||
it.copy(
|
||||
isPlaying = true,
|
||||
currentPosition = it.currentPosition + 1000L,
|
||||
currentPosition = it.currentPosition + FAKE_PLAYED_DURATION_MS,
|
||||
duration = FAKE_TOTAL_DURATION_MS,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user