dxvid-pts / miniplayer

A lightweight flutter package to simplify the creation of a miniplayer.
https://pub.dev/packages/miniplayer
MIT License
106 stars 79 forks source link

How to use the better player package in this package? #25

Open AhmadFalahian opened 2 years ago

AhmadFalahian commented 2 years ago

I have designed an application in which we have a movie player that has used the better player package and I want the player display to continue at the bottom of the page when the back button is pressed. Similar to YouTube, but when I use this package to resolve this issue, I get an error A VideoPlayerController was used after being disposed. This error appears when the player is minimized and I make it full screen.

my code is:


class MyHomePage extends StatefulWidget {
  MyHomePage({Key? key}) : super(key: key);

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  BetterPlayerController? _betterPlayerController;

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    BetterPlayerDataSource betterPlayerDataSource = BetterPlayerDataSource(
        BetterPlayerDataSourceType.network,
        "https://cdn.hobyna.app/media/videos/2022-04-17/283108507127672349878.mp4");
    _betterPlayerController = BetterPlayerController(
        const BetterPlayerConfiguration(),
        betterPlayerDataSource: betterPlayerDataSource);
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Stack(
        children: [
          Miniplayer(
            minHeight: 150,
            maxHeight: MediaQuery.of(context).size.height,
            builder: (h, i) {
              final bool miniplayer = i < miniplayerPercentageDeclaration;
              if (!miniplayer) {
                return AspectRatio(
                  aspectRatio: 16 / 9,
                  child: BetterPlayer(
                    controller: _betterPlayerController!,
                  ),
                );
              } else {
                return SizedBox(
                  height: 150.0,
                  width: 100.0,
                  child: AspectRatio(
                    aspectRatio: 16 / 9,
                    child: BetterPlayer(
                      controller: _betterPlayerController!,
                    ),
                  ),
                );
              }
            },
          )
        ],
      ),
    );
  }
}
1041harpreet commented 6 months ago

If you want to play video when mini player state is changed. for eg if when user click on mini player then play same video and vice verse, you need to move your video controller to provider so that it does not dispose on disposing of page