问题
I'm working with remote android TV To catch event when use press remote button I use this code:
public boolean dispatchKeyEvent(KeyEvent event) {
Log.d("LOG", "Number repeate count = " + event.getRepeatCount());
if (event.getAction() == KeyEvent.ACTION_DOWN) {
switch (event.getKeyCode()) {
case KeyEvent.KEYCODE_1:
exoPlayerManager.showControllerView();
if (event.getRepeatCount() > 0) {
if (videoPlayerView.getPlaybackControlView().getPlayer().getPlaybackParameters().speed >= 64) {
((TextView)videoPlayerView.getPlaybackControlView().findViewById(R.id.exo_rate)).setVisibility(View.GONE);
videoPlayerView.getPlaybackControlView().getPlayer().setPlaybackParameters(new PlaybackParameters(1, 1.0f));
} else {
videoPlayerView.getPlaybackControlView().getPlayer().setPlaybackParameters(new PlaybackParameters(2 * videoPlayerView.getPlaybackControlView().getPlayer().getPlaybackParameters().speed, 1.0f));
}
((TextView)videoPlayerView.getPlaybackControlView().findViewById(R.id.exo_rate)).setText(videoPlayerView.getPlaybackControlView().getPlayer().getPlaybackParameters().speed + "X");
}else if (videoPlayerView.getPlaybackControlView() != null) {
return videoPlayerView.getPlaybackControlView().dispatchKeyEvent(event);
}
break;
I see that when I press 1 button on remote, getRepeateCount()
always return 0.
I think if i pressed duplicate it should be greater 0.
What is wrong here ?
回答1:
When you press a key, release it, and then press it again, you will receive two ACTION_DOWN
events, and getRepeatCount()
will return 0 for both. To see a non-zero getRepeatCount()
value, you have to hold down the key long enough that it starts repeating.
You can think about it like this. If I type "aaaaaaaaaa" into this text field by pressing and releasing my keyboard's A key 10 times, I'll get 10 events, each with a repeat count of zero. But if I hold my A key down long enough that I start getting multiple "a"s, then I'll get 10 events, each with an increasing repeat count.
来源:https://stackoverflow.com/questions/47825114/keyevent-getrepeatcount-always-return-0