Status Update
Comments
su...@google.com <su...@google.com>
kl...@google.com <kl...@google.com> #2
there are some image for help
au...@gmail.com <au...@gmail.com> #3
hello?
gy...@google.com <gy...@google.com> #4
do...@google.com <do...@google.com> #5
Sure it'll work, but it sends the message that our media libraries aren't Kotlin-friendly.
This could be an excellent opportunity for a Media KTX library. Many of our other AndroidX libraries have KTX libs for similar reasons (ListenableFuture
s with suspend functions.
gy...@google.com <gy...@google.com> #7
Hi Don, I see the point of Kotlin-friendliness. I do think it's nice to provide ktx if it benefits users.
I'm wondering how much it will benefit the developers to provide suspend extension functions wrapping APIs returning ListenableFuture. Then, the code would be:
implementation 'androidx.media2:media2-session-ktx:1.2.0'
mediaController.awaitPlay() // suspend function
It will need the same effort as:
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-guava:1.5.20'
mediaController.play().await()
I think the latter would be more flexible/resilient if there were some missing wrappers in the media ktx.
From the class design point of view, ListenableFuture is a common interface defined in Guava not specifically in the media library. So, extension for ListenableFuture should be in a Guava extension for more consistant interface. If there were two different libraries that expose ListenableFutures and have their own Kotlin extensions to wrap the ListenableFutures as suspend functions, the code might have inconsistency using the ListenableFutures.
Please let me know if I'm missing something or if there are other examples for extensions than ListenableFuture.
gy...@google.com <gy...@google.com>
ba...@google.com <ba...@google.com> #8
There is AndroidX Concurrent that has a Kotlin extension that adds a suspend function await()
for ListenableFutures
. With this, integration into Coroutines was easy for me. I'm not super experienced with Kotlin but this was helpful for integrating with Coroutines:
Sample (pseudo) code:
init {
viewModelScope.launch {
val mediaItemList = mediaBrowser.getChildren(parentId, 0, 100, null).value!!
// do something with the mediaItemList
}
}
Description
A lot of the media APIs use callbacks and
ListenableFuture
s for providing results. It would be very helpful for Kotlin developers to build out a ktx library to go along with this that wraps these calls assuspend
functions.