media-kit / media-kit

A cross-platform video player & audio player for Flutter & Dart.
https://github.com/media-kit/media-kit
MIT License
893 stars 126 forks source link

Keyboard shortcuts disabled once the focus is moved to other widgets #790

Open songbirdzz opened 3 weeks ago

songbirdzz commented 3 weeks ago

Description

Unable to move focus back to Video once it's moved to other widgets, thus making keyboard shortcuts disabled.

Reproduce code

import 'package:flutter/material.dart';
import 'package:media_kit/media_kit.dart'; // Provides [Player], [Media], [Playlist] etc.
import 'package:media_kit_video/media_kit_video.dart'; // Provides [VideoController] & [Video] etc.

void main() {
  WidgetsFlutterBinding.ensureInitialized();
  // Necessary initialization for package:media_kit.
  MediaKit.ensureInitialized();
  runApp(
    const MaterialApp(
      home: MyScreen(),
    ),
  );
}

class MyScreen extends StatefulWidget {
  const MyScreen({Key? key}) : super(key: key);
  @override
  State<MyScreen> createState() => MyScreenState();
}

class MyScreenState extends State<MyScreen> {
  // Create a [Player] to control playback.
  late final player = Player();
  // Create a [VideoController] to handle video output from [Player].
  late final controller = VideoController(player);

  @override
  void initState() {
    super.initState();
    player.open(Media(
        'https://user-images.githubusercontent.com/28951144/229373695-22f88f13-d18f-4288-9bf1-c3e078d83722.mp4'));
  }

  @override
  void dispose() {
    player.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Row(
      children: [
        Expanded(
            flex: 2,
            child: Video(
              controller: controller,
            )),
        Expanded(
            child: Container(
          child: TextField(),
        )),
      ],
    );
  }
}

Reproduce steps:

  1. Test keyboard shortcuts upon build such as space to pause/play the video, it's normal at this step.
  2. Click the TextField to move focus to it.
  3. Click the Video widget again and try to use keyboard shortcuts, now they wouldn't work unless fullscreen mode is entered.
abdelaziz-mahdy commented 3 weeks ago

i have tested your sample code, and when focus is on text field yes the shortcuts doesn't work, but when i tap on the video widget they work again, which looks like the excepted behaviour (Note: i am testing on macOS)

songbirdzz commented 3 weeks ago

I'm on Windows, and also reproduced it at https://flutlab.io/ using its default web build.

abdelaziz-mahdy commented 3 weeks ago

I had a problem with focus and flutter web before, can you test it using windows build if not tested on it? And feel free to suggest a fix in a pr

songbirdzz commented 3 weeks ago

Windows build also has this issue, I'll try to look into it.