Closed Ethan1983 closed 1 week ago
If I understand the proposal correctly, this should already work by calling MediaBrowser.subscribe
first, which returns onChildrenChanged
with the total number of children and then the browser can request the items individually with getChildren(..., pageSize=1,..)
. Would that work for your use case?
If I understand the proposal correctly, this should already work by calling
MediaBrowser.subscribe
first, which returnsonChildrenChanged
with the total number of children and then the browser can request the items individually withgetChildren(..., pageSize=1,..)
. Would that work for your use case?
Thanks. So in this case, when the service doesn't have the data in onChildrenChanged
and it will return a ListenableFuture. How will the loading progress (like % downloaded) be relayed to the client?
onChildrenChanged
will just notify about the number of items, which should ideally be quick. And the the MediaBrowser
can do something like:
public void onChildrenChanged(..., int ItemCount,...) {
AtomicInteger loadedItems = new AtomicInteger(0);
updateProgressBar(0);
for (int i = 0; i < itemCount; i++) {
ListenableFuture<..> childFuture = getChildren(..., /* page */ i, /* pageSize */ 1, ...);
Futures.addCallback(childFuture, new FutureCallback<>() {
public void onSuccess(...) {
loadedItems++;
updateProgressBar(loadedItems / itemCount);
}
public void onFailure(...) { }
});
}
}
onChildrenChanged
will just notify about the number of items, which should ideally be quick. And the theMediaBrowser
can do something like:public void onChildrenChanged(..., int ItemCount,...) { AtomicInteger loadedItems = new AtomicInteger(0); updateProgressBar(0); for (int i = 0; i < itemCount; i++) { ListenableFuture<..> childFuture = getChildren(..., /* page */ i, /* pageSize */ 1, ...); Futures.addCallback(childFuture, new FutureCallback<>() { public void onSuccess(...) { loadedItems++; updateProgressBar(loadedItems / itemCount); } public void onFailure(...) { } }); } }
In our case, the total number of items isn't known in advance and determining that itself takes a while from the service end.
In our case, the total number of items isn't known in advance and determining that itself takes a while from the service end.
In this case I can only recommend sending sendCustomCommand, as you already pointed out yourself. Do you have another API in mind that would you would really like to see in the library? I can't really see a good way to fit your feature request into the existing APIs, so I'm curious if you already had something in mind.
In our case, the total number of items isn't known in advance and determining that itself takes a while from the service end.
In this case I can only recommend sending sendCustomCommand, as you already pointed out yourself. Do you have another API in mind that would you would really like to see in the library? I can't really see a good way to fit your feature request into the existing APIs, so I'm curious if you already had something in mind.
On top of my head, APIs could leverage the existing notify pattern from service end, notifyLoading(Bundle)
, notifyError(Bundle)
and clients could have callbacks similar to onChildrenChanged
.
Thanks, in this case sending a custom message is probably most useful still because the requirements for such a loading callback may be quite different between apps. I can only imagine that having a dedicated method makes sense when where is a generic controller that can display the progress from all apps. The proposed notifyLoading(bundle)
method is very similar to sendCustomCommand(progressCommand, bundle)
in your code in the end as well.
In the interest of providing a reactive interface, you may also want to publish a small number of items initially, and then later call notifyChildrenChanged
once your backend has loaded more items.
Closing the issue under the assumption that the question is answered for now.
Apologies, just getting to this. Yes custom message does work fine, just that it doesn't stand out automatically as a first citizen API (like how list view's holder was never first class and RecyclerView had changed that with out of box ViewHolder API).
MediaLibraryService to support loading progress feedback to connected browsers
MediaLibraryService loads data from the filesystem and knows the total number of files in advance and would like to provide progress feedback to connected browsers. Likewise, would also like to notify of any errors.
Proposed solution
MediaLibraryService to support a loading and error API/protocol which could be invoked by the service for every onGetChildren request. This could support a bundle for any custom application specific payload. Connected browsers can use the payload to update UI to give more useful feedback than just displaying an infinite loading indicator. Load, data and error states is a typical flow in any application and an out of box support would be nice.
Alternatives considered
Alternative is to use custom messages via sendCustomCommand on the media session and this needs some coordination on the browser side between different callbacks. Also, this kind of custom solutions is duplicated across different applications.