uamp icon indicating copy to clipboard operation
uamp copied to clipboard

How to reconnect/reload (media) in same session after Network lost!

Open cingh-jasdeep opened this issue 6 years ago • 5 comments

Hi

Thanks for this helpful sample. I am building an online radio streaming app. Very similar to the sample

UAMP: Kotlin version Android Version: Pie Device: Pixel 1

I wanted to know how the MediaSession can handle exceptions in the following cases? (currently it does nothing)

  1. When there is no internet connection and a client tries to onLoadChildren? Right now it returns null, so no items. But how to reload onLoadChildren when internet connection resumes.

  2. After Catalog loaded, internet goes away while playing? Right now Playback goes to error state and does not return How to come back to normal state when internet connection resumes.

Thanks for your help!

cingh-jasdeep avatar Feb 28 '19 12:02 cingh-jasdeep

@cingh-jasdeep I solved the first problem by calling when I want to update media list

MediaBrowserServiceCompat.notifyChildrenChanged(String parentId)

Calling this notifies all connected media browsers that the children of the specified parent id have changed in some way.

After this onLoadChildren() will be called again.

popivyurii avatar Mar 26 '19 09:03 popivyurii

@YuriPopiv Hi Yuri, do you happen to have a committed example of this in action? Or could you perhaps point me to a working example? I'm currently trying to refresh custom JSON content using a wrapper activity and would like a way to resubscribe to the Music service. Any help you could provide would be much appreciated. Thank you.

ponder-bar avatar May 14 '19 14:05 ponder-bar

@ponder-bar First you need update catalog in the JsonSource object with media content.

Then, for example, add a method to MediaSessionConnection

fun resubscribe() {
        mediaBrowser.unsubscribe(parentId, callback)
        mediaBrowser.subscribe(parentId, callback)
    }

    

after this onLoadChildren( parentMediaId: String, result: androidx.media.MediaBrowserServiceCompat.Result<List<MediaItem>>) method in your MusicService will be triggered and result.sendResult(children) will be called with new content

popivyurii avatar May 14 '19 15:05 popivyurii

@YuriPopiv Thank you, this is a definitely a help, though as a Kotlin beginner I am wondering where I would theoretically call this resub function. Thanks again.

ponder-bar avatar May 14 '19 16:05 ponder-bar

@ponder-bar I am facing same thing , Have you done it ??

richanshah avatar Feb 05 '20 10:02 richanshah