Fix coroutine scope (#4820)
* Inject the session scope instead of the application scope where it's possible. * Create AppCoroutineScope annotation to let developers explicitly choose the appropriate CoroutineScope when injecting one.
This commit is contained in:
parent
36c7c7ab9b
commit
5f191d9f9c
58 changed files with 172 additions and 72 deletions
|
|
@ -15,6 +15,7 @@ import io.element.android.libraries.audio.api.AudioFocus
|
|||
import io.element.android.libraries.audio.api.AudioFocusRequester
|
||||
import io.element.android.libraries.di.RoomScope
|
||||
import io.element.android.libraries.di.SingleIn
|
||||
import io.element.android.libraries.di.annotations.SessionCoroutineScope
|
||||
import io.element.android.libraries.mediaplayer.api.MediaPlayer
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.FlowPreview
|
||||
|
|
@ -37,7 +38,8 @@ import kotlin.time.Duration.Companion.seconds
|
|||
@SingleIn(RoomScope::class)
|
||||
class DefaultMediaPlayer @Inject constructor(
|
||||
private val player: SimplePlayer,
|
||||
private val coroutineScope: CoroutineScope,
|
||||
@SessionCoroutineScope
|
||||
private val sessionCoroutineScope: CoroutineScope,
|
||||
private val audioFocus: AudioFocus,
|
||||
) : MediaPlayer {
|
||||
private val listener = object : SimplePlayer.Listener {
|
||||
|
|
@ -50,7 +52,7 @@ class DefaultMediaPlayer @Inject constructor(
|
|||
)
|
||||
}
|
||||
if (isPlaying) {
|
||||
job = coroutineScope.launch { updateCurrentPosition() }
|
||||
job = sessionCoroutineScope.launch { updateCurrentPosition() }
|
||||
} else {
|
||||
audioFocus.releaseAudioFocus()
|
||||
job?.cancel()
|
||||
|
|
|
|||
|
|
@ -423,7 +423,7 @@ class DefaultMediaPlayerTest {
|
|||
audioFocus: AudioFocus = FakeAudioFocus(),
|
||||
): DefaultMediaPlayer = DefaultMediaPlayer(
|
||||
player = simplePlayer,
|
||||
coroutineScope = backgroundScope,
|
||||
sessionCoroutineScope = backgroundScope,
|
||||
audioFocus = audioFocus,
|
||||
)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue