Как назначить пользовательские кнопки ImageView кнопкам D-Pad? - PullRequest
0 голосов
/ 05 августа 2020

Как я могу назначить ImageView (Play / Pause), определенный в controller_layout_id PlayerView, кнопке пульта дистанционного управления телевизора?

Я попытался настроить setOnKeyListener (), как показано ниже, в моем действии:

bPlayButton.setOnKeyListener(new View.OnKeyListener() {
        @Override
        public boolean onKey(View view, int keyCode, KeyEvent keyEvent) {
            if (keyCode == KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE){
                mPlayerGlue.play();
            }
            return false;
        }
    });

Я определяю bPLayButton в методе OnCreate моей деятельности следующим образом:

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    if (savedInstanceState == null) {

        bPlayButton = mPlayerView.findViewById(R.id.exo_play);}`

Вот моя XML настройка для Controller_Layout:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="@dimen/video_content_width"
android:layout_height="@dimen/video_content_height"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="@color/transparent_background">

<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:layout_centerInParent="true">

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/exo_rew"
        android:layout_marginEnd="16dp"
        android:src="@drawable/ic_rew"/>

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/exo_play"
        android:src="@drawable/ic_play"/>

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/exo_pause"
        android:src="@drawable/ic_pause"/>

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/exo_ffwd"
        android:layout_marginStart="16dp"
        android:src="@drawable/ic_ffwd"/>
</LinearLayout>

Я последовал примеру показано в этом видео ниже: https://www.youtube.com/watch?v=MdQOXoEMLOs&t=173s

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...