google / google/ExoPlayer

Is it possible to receive dispatch commands from Voice? I am migrating from 2.12.1 to 2.16.1

Open
#10,056 5 comments 0 reactions 1 assignee Claimed by @marcbaechinger View on GitHub
question
Dominant language
Java
Stars
21.9k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

Hi, I am migrating from library 2.12.1 to 2.16.1, I found out the ControlDispatcher was completely removed.

I was using the ControlDispatcher to intercept the voice commands for play/pause to send the appropriate Analytics tracking message. Now I am kind of lost how to detect and intercept the voice commands to track them, in fact, complete media session
commands stopped working because there is not control dispatcher, so i am wondering if there is a tutorial or documentation about how to do this, the google documentation page still makes reference to old control dispatchers.

I read in the ReleaseNotes.md file that i could use a forwarding player, but i am not sure exactly how to do it, this is the old code i used to track the voice commands:

```
class CustomControlDispatcher(val videoPresenter: VideoPresenter) : ControlDispatcher {

val titleId: String?
get() =videoPresenter.currentTitle()

override fun dispatchSetPlayWhenReady(player: Player, playWhenReady: Boolean): Boolean {
// change state of player manually
player.playWhenReady = playWhenReady
// Tracking external commands such as voice commands in AndroidTV
AnalyticsTracker.track("voice_cmd_play", titleId)
return true
}

override fun dispatchSeekTo(player: Player, windowIndex: Int, positionMs: Long): Boolean {
// set position of player manually
player.seekTo(windowIndex, positionMs)
// Track in analytics the voice command
AnalyticsTracker.track("voice_cmd_seek_to", titleId, windowIndex, positionMs)
return true
}

```
I just attached this custom control dispatcher to the media session and i started receiving commands, i tested them with:
"adb shell media dispatch pause" and now nothing works, the player doesn't receive the commands. I extended a class from ForwardingPlayer and set its player to my video player but i do not receive any message at all, can somebody give me some light about how to replace the control dispatcher?

This is the class i created:

```
class VoiceCommandsDispatcher(player: Player) : ForwardingPlayer(player) {

override fun setPlayWhenReady(playWhenReady: Boolean) {
super.setPlayWhenReady(playWhenReady)

Log.e("--->", " ---> VoiceCommandsDispatcher: setPlayWhenReady: $playWhenReady")
}
}

override fun seekTo(mediaItemIndex: Int, positionMs: Long) {
super.seekTo(mediaItemIndex, positionMs)

Log.e("--->", " ---> VoiceCommandsDispatcher: seekTo: $mediaItemIndex, $positionMs")
}
}
```
I will really appreciate any help on this

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.