android / uamp

A sample audio app for Android
Apache License 2.0
13.1k stars 3.76k forks source link

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

Open cingh-jasdeep opened 5 years ago

cingh-jasdeep commented 5 years ago

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!

popivyurii commented 5 years ago

@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 thisonLoadChildren() will be called again.

ponder-bar commented 5 years ago

@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.

popivyurii commented 5 years ago

@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

ponder-bar commented 5 years ago

@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.

richanshah commented 4 years ago

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