mirror of
https://github.com/Novaloop-AG/element-x-android.git
synced 2026-11-03 16:10:00 +00:00
Voice message MediaPlayer: wait until player is ready (#1772)
Change to `MediaPlayer` API to allow waiting for the player to be in a ready state. This is needed in order to perform some tasks (e.g. read the media duration, seek) after changing the media file.
This commit is contained in:
+11
-5
@@ -30,13 +30,15 @@ interface MediaPlayer : AutoCloseable {
|
||||
val state: StateFlow<State>
|
||||
|
||||
/**
|
||||
* Acquires control of the player and starts playing the given media.
|
||||
* Initialises the player with a new media item, will suspend until the player is ready.
|
||||
*
|
||||
* @return the ready state of the player.
|
||||
*/
|
||||
fun acquireControlAndPlay(
|
||||
suspend fun setMedia(
|
||||
uri: String,
|
||||
mediaId: String,
|
||||
mimeType: String,
|
||||
)
|
||||
): State
|
||||
|
||||
/**
|
||||
* Plays the current media.
|
||||
@@ -59,6 +61,10 @@ interface MediaPlayer : AutoCloseable {
|
||||
override fun close()
|
||||
|
||||
data class State(
|
||||
/**
|
||||
* Whether the player is ready to play.
|
||||
*/
|
||||
val isReady: Boolean,
|
||||
/**
|
||||
* Whether the player is currently playing.
|
||||
*/
|
||||
@@ -75,8 +81,8 @@ interface MediaPlayer : AutoCloseable {
|
||||
*/
|
||||
val currentPosition: Long,
|
||||
/**
|
||||
* The duration of the current content.
|
||||
* The duration of the current content, if available.
|
||||
*/
|
||||
val duration: Long,
|
||||
val duration: Long?,
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user