0

I'm trying to create a video player with controls for Android TV with Flutter

The basic video_player is working: https://gist.github.com/andraskende/195e746716e5e4e978356abb09e66a37

Would like to enhance the controls:

  • video plays: show controls for first 5 seconds, then hide controls..
  • keypress on D-pad controls would appear (play/pause, forward rewind)
  • video paused: show controls, if back pressed once hide controls

I tried to add RawKeyboardListener to listen on a keypress on remote but then the controls are not selectable as the RawKeyboardListener takes over..

I guess when the controls are hidden I need RawKeyboardListener to bring up the controls and disable the RawKeyboardListener so the control buttons can be selected.

Any help is greatly appreciated.

Thanks, Andras

5
  • Your question is confusing. You say it's for Android TV, but then you mentioned a D-Pad, a keyboard and an Escape key. To my knowledge there is no Escape key on Android devices. What is a D-Pad on an Android TV? Commented Apr 15, 2020 at 15:49
  • Thanks for the help, will add a youtube video later to explain better. The primary navigation method on Android TV is through the directional pad (called a D-pad). This pad limits movement to up, down, left, and right directional hardware buttons. The D-pad transfers focus from one object to the nearest object in the direction of the button pressed. Commented Apr 15, 2020 at 17:52
  • But that's with a remote, right? Commented Apr 15, 2020 at 18:48
  • Yes I need this withe the remote which has the dpad arrow keys... Thanks Commented Apr 15, 2020 at 19:16
  • I'm not sure how Flutter handles remote input. I'm assuming it takes it as some sort of physical key. Commented Apr 15, 2020 at 20:15

1 Answer 1

2

I faced similar kind of issue where I fixed it with below code:

void _onKey(RawKeyEvent e) {
controls();

if (e.runtimeType.toString() == 'RawKeyDownEvent') {
  switch (e.logicalKey.debugName) {
    case 'Media Play Pause':
    case 'Select':
      setState(() {
        if (_videoViewController.value.isPlaying) {
          _videoViewController.pause();
        } else {
          _videoViewController.play();
        }
      });
      break;
  }
}`

Now if you wanted to have a fast forward or back just use the RawKeyboardListener with specific case to handle it.

You can also use your D-PAD keys to perform such action.

Sign up to request clarification or add additional context in comments.

1 Comment

I tried mentioned code but somehow its not working

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.