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

遥控器ok键无响应 KEYCODE_DPAD_CENTER #2124

Closed
pyp163 opened this issue Jul 9, 2019 · 9 comments
Closed

遥控器ok键无响应 KEYCODE_DPAD_CENTER #2124

pyp163 opened this issue Jul 9, 2019 · 9 comments

Comments

@pyp163
Copy link

pyp163 commented Jul 9, 2019

问题描述:

android 9.0
布局:
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.vod.activity.Main2Activity">

<com.publics.video.EmptyControlVideo
    android:id="@+id/video_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:focusable="false"
    android:focusableInTouchMode="false">

</com.publics.video.EmptyControlVideo>

</androidx.constraintlayout.widget.ConstraintLayout>

Activity:
public class Main2Activity extends BaseActivity {

private EmptyControlVideo video;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main2);
    video = findViewById(R.id.video_view);
}

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    LogDog.i("------键值--------"+keyCode);
    return super.onKeyDown(keyCode, event);
}

}
遥控器按ok无响应:
ok键值:TvWindowManager: key event key = KEYCODE_DPAD_CENTER
按上下左右键有响应有打印Log

问题机型/系统:

某电视机顶盒子 Android9.0

GSY依赖版本

implementation 'com.shuyu:gsyVideoPlayer-java:7.0.1'

@CarGuo
Copy link
Owner

CarGuo commented Jul 9, 2019

em……我不认为这个是项目的问题

@pyp163
Copy link
Author

pyp163 commented Jul 9, 2019

但是我去掉播放器按ok键正常
<com.publics.video.EmptyControlVideo
android:id="@+id/video_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:focusable="false"
android:focusableInTouchMode="false">

</com.publics.video.EmptyControlVideo>

@pyp163
Copy link
Author

pyp163 commented Jul 9, 2019

android7.0正常

@CarGuo
Copy link
Owner

CarGuo commented Jul 9, 2019

#1302

@pyp163
Copy link
Author

pyp163 commented Jul 9, 2019

#1302 的代有参考过
因为不让EmptyControlVideo有焦点不需要实现onKeyDown
android:focusable="false"
android:focusableInTouchMode="false"
onKeyDown由Activity来控制,上下左右键可以响应,就ok键不响应很尴尬

@CarGuo
Copy link
Owner

CarGuo commented Jul 17, 2019

em····这个还真不是很清楚

@CarGuo CarGuo closed this as completed Jul 30, 2019
@xwlcn
Copy link

xwlcn commented Jan 29, 2024

@pyp163 @CarGuo 2024了这个问题还是存在...原因是OK键被播放器的onClick事件拦截了,因为按下OK键触发了点击事件,导致Activity无法监听到OK键按下的事件。一般按下OK键是用来控制播放与暂停,直接在onClick里判断,这是我的写法:

override fun onClick(v: View?) {
        super.onClick(v)
        v?.let {
            when (it.id) {
                R.id.tv_projection -> {

                    if (!this::devicesSetting.isInitialized)
                        Toast.makeText(activityContext, "未找到设备!请确保手机与TV连接同一网络.", Toast.LENGTH_LONG).show()
                    else
                        devicesSetting.show()
                }
                R.id.video_speed -> {
                    speedSetting.show()
                }
                R.id.lines -> {
                    linesSetting.show()
                }
                R.id.video_scale -> {
                    scaleSetting.show()
                }
                else -> {
                    if (MainActivity.deviceType == 2) {
                        if (mCurrentState == CURRENT_STATE_PLAYING) {
                            onVideoPause()
                        } else {
                            onVideoResume()
                        }
                    }
                }
            }
        }
    }

或者下面这种解决办法

因为不让EmptyControlVideo有焦点不需要实现onKeyDown
android:focusable="false"
android:focusableInTouchMode="false"
onKeyDown由Activity来控制,上下左右键可以响应,就ok键不响应很尴尬

至于这个问题,是因为默认焦点根本不是在EmptyControlVideo上,而是@+id/surface_container上,需要将surface_container禁止获取焦点,而不是EmptyControlVideo,将surface_container禁止获取焦点之后再将默认焦点设置到EmptyControlVideo上,就可以直接在EmptyControlVideo里监听onKeyDown事件了,若是想在Activity上监听onKeyDown,那么久只需要将surface_container禁止获取焦点即可。

@CarGuo
Copy link
Owner

CarGuo commented Jan 31, 2024

@xwlcn demo 现在提供了 https://github.com/CarGuo/GSYVideoPlayer/blob/master/app/src/main/java/com/example/gsyvideoplayer/video/TvVideoPlayer.java

另外就像你说的,override onClick 处理

@xwlcn
Copy link

xwlcn commented Jan 31, 2024

@xwlcn demo 现在提供了 https://github.com/CarGuo/GSYVideoPlayer/blob/master/app/src/main/java/com/example/gsyvideoplayer/video/TvVideoPlayer.java

另外就像你说的,override onClick 处理

嗯 这个快进快退我参考了一下,并没有直接继承这个类,不知道是不是我版本太低的原因还是代码本身有点问题,经常会出现快进或快退无效:就是屏幕中心显示了最后快进或者快退的时间点,但最后实际没有快进快退或者时间对不上,最后我去掉了一些逻辑就好了。
还有个明显的问题就是快进快退最后是匀速的很慢,这有点不太符合操作习惯,比如想快进或者快退很长一段时间,那么需要按很久,应该改成加速度那样,在第一次按下时记录时间,每次按键事件里用当前时间减去第一次按下的时间差乘以那个匀速快进或者快退的值就可以了。

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

No branches or pull requests

3 participants