Skip to content
This repository has been archived by the owner on Nov 14, 2018. It is now read-only.

Convenience DSL for Media Controller Callback event handling #574

Open
dpmedeiros opened this issue Jun 8, 2018 · 0 comments
Open

Convenience DSL for Media Controller Callback event handling #574

dpmedeiros opened this issue Jun 8, 2018 · 0 comments

Comments

@dpmedeiros
Copy link

dpmedeiros commented Jun 8, 2018

Hi,

Internally for our project I have written a simple Kotlin DSL to make dealing with state change events in media controller callbacks simpler and easier to write/read.

As an example, the DSL allows you to do things like the following:

val canceler = session.whenSession { // start configuring a listener for a media session
    stateChanges { state -> // whenever the state changes...
        configureUIForState(state) // ...update the UI for the new state
    }

   startsPlaying { // when playing state is entered...
        onStartPlaying() //...handle it
   }

   metadataChanges { metadata -> // when metadata for the session changes...
       setupUI(metadata) // ...update the UI
    }
    
    positionChanges { position -> // when media position changes...
        updateSeekProgress(position) // ...update seek progress
    }
}
// ... some time later ...
canceler.stopListening() // stop listening to events

A first draft implementation (missing features that could be added and unit tests) is here

I'm wondering if you will consider this an appropriate addition to ktx and would like to get your feedback before I put more work into it.

I do however realize you are not yet supporting new APIs for the support library

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant