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

Convenience DSL for Media Controller Callback event handling #574

@dpmedeiros

Description

@dpmedeiros

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions