Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Send timed metadata to controller #948

Open
thetwom opened this issue Jan 6, 2024 · 2 comments
Open

Send timed metadata to controller #948

thetwom opened this issue Jan 6, 2024 · 2 comments

Comments

@thetwom
Copy link

thetwom commented Jan 6, 2024

I have a custom player built on top of SimpleBasePlayer. From this player, I want to send frequent time-accurate metadata to attached controllers (especially the UI controller). It seems like setTimedMetadata would be an appropriate solution. So within the simple base player I update and invalidate the state as follows.

private var state = State.Builder().......build()

private fun sendTimedMetadata(metadataEntry: Metadata.Entry) {
     val time = 1000L
     state = state.buildUpon()
            .setTimedMetadata(Metadata(time, metadataEntry))
            .build()
      invalidateState()
}

where sendTimedMetadata is called, when I want to share the metadata.

When I attach an Player.Listener to the directly to the player, this it receives the metadata on the onMetadata-callback as expected.

However, when I use the regular setup with MediaSession and MediaSessionService and trying to connect a MediaController from an activity, the onMetadata is not called for the controller. Other state changes like isPlaying are working fine.

Am I missing something here or is this not expected to work? Maybe there are alternatives or better ways to send regular events (could be 10 events per second) to an activity? There seems to be broadcastCustomCommand of a MediaSession but currently I did not find a way to listen to such commands by controllers.

@icbaker
Copy link
Collaborator

icbaker commented Jan 9, 2024

Arbitrary Metadata.Entry objects are not sent from MediaSession to MediaController, so what you're observing is expected.

@marcbaechinger might have thoughts on the best way to send time-accurate info from a session to a controller.

@thetwom Can you give some info about what these timed events that you want to send represent? It might help guide us towards a solution.

@icbaker icbaker assigned marcbaechinger and unassigned icbaker Jan 9, 2024
@thetwom
Copy link
Author

thetwom commented Jan 9, 2024

Thanks a lot for taking the time and answering my question. Good to know, that things are working as expected (even though it would have been nice for me if it worked :-).

I guess my case is rather exotic, so I don't know if I want to take your time for finding a solution. Still, I will quickly give a description:

My player is not playing regular media, but it is a metronome, which plays sounds at regular time intervals (like a "clicking" sound 4 times a second). When the app is at the foregound, visual feedback for the "clicks" is required. The player implemention is able to emit the corresponding information shortly before the click starts and I am looking for a way to bring this information to the UI.

Timed metadata seemed like something which would exactly fit the needs, but besides of not being transferred to the controller, I am unsure, if it would able to deliver information reliable within a small enough latency (say 0.1s).

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

No branches or pull requests

3 participants