-
Notifications
You must be signed in to change notification settings - Fork 467
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Idiomatic kotlin API for Player Events (media3-common-ktx) #2027
Comments
Hi @Ethan1983, Thank you very much for your suggestion. Please first take a look at the KDoc we provided for the media/libraries/common_ktx/src/main/java/androidx/media3/common/PlayerExtensions.kt Lines 56 to 81 in 76088cd
As you can see, there is a note on why we chose to go ahead with a However, I understand where you are coming from - Kotlin documentation on https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/callback-flow.html and https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/suspend-cancellable-coroutine.html is definitely clear in that respect and it might look like we are abusing some sort of a loophole with A Flow with all the events would also not adhere to a single responsibility principle, each consumer would still have to filter out the ones that they want. At this point you might wonder why not create 30 flows for all sorts of events, which is when timing guarantees become debatable - having to use https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/combine.html again leads you to potentially illegal states. We understand that, as app developers, you will have received a lot of Android guidance on using Flows. It is still the case that Flows and Channels are great structures for a data-business layer exchange. However, as library developers, we have to work around One thing to mention is that with the current implementation, you can create the Flows that you need (if you dare to go down that path after all I've explained above), since you have a lower-level construct. However, you might notice how easy it is to use
|
Thanks for the Kdoc. Is there a way to reproduce the delay when using Flow? Would a SharedFlow (without any replay) have helped when dealing with multiple consumers?
Isn't this already the case even with the callback? Multiple consumers are effectively filtering with the
|
Use case description
Please provide a idiomatic kotlin API for player events using Flow in androidx.media3:media3-common-ktx
Proposed solution
Current API is a suspend API with a callback. suspend API is typically meant for a one-time async request. For a stream of player events, please provide a
Flow<Player.Events>
using callbackFlow.Alternatives considered
The text was updated successfully, but these errors were encountered: