jhomlala / betterplayer

Better video player for Flutter, with multiple configuration options. Solving typical use cases!
Apache License 2.0
932 stars 1.04k forks source link

[BUG] player works unexpectedly #1308

Open Kunal0127 opened 5 months ago

Kunal0127 commented 5 months ago
  1. player only plays audio not video in simulator.

  2. isPictureInPictureSupported() returns false even the PIP is supported device: tried on:

    • ios simulator [iPad Pro (12.9-inch) (6th genertion)]
    • physical device [iPhone 6s Plus]

I add two print in lib/src/core/better_player_controller.dart > enablePictureInPicture()

...
.
  Future<void>? enablePictureInPicture(GlobalKey betterPlayerGlobalKey) async {
    if (videoPlayerController == null) {
      throw StateError("The data source has not been initialized");
    }
    debugPrint("1 is pip supported delete it letter line : 1062: ${await videoPlayerController!.isPictureInPictureSupported()}");
    final bool isPipSupported =
        (await videoPlayerController!.isPictureInPictureSupported()) ?? false;
    debugPrint("2 is pip supported delete it letter line : 1066: $isPipSupported");

    if (isPipSupported) {
      _wasInFullScreenBeforePiP = _isFullScreen;
...
.

my code

import 'package:better_player/better_player.dart';
import 'package:flutter/material.dart';
import 'package:flutterpip02/screen/second_screen.dart';

class HomeScreen extends StatefulWidget {
  const HomeScreen({super.key, required this.title});

  final String title;

  @override
  State<HomeScreen> createState() => _HomeScreenState();
}

class _HomeScreenState extends State<HomeScreen> {
  late BetterPlayerController _betterPlayerController;
  late Future<void> _initializeVideoPlayerFuture;
  GlobalKey _betterPlayerKey = GlobalKey();

  @override
  void initState() {
    super.initState();
    _betterPlayerController = BetterPlayerController(
        BetterPlayerConfiguration(
          autoDispose: true,
          autoPlay: true,
          errorBuilder: (context, errorMessage) {
            debugPrint("error is $errorMessage");
            return Text("$errorMessage");
          },
        ),
        betterPlayerDataSource: BetterPlayerDataSource(
            BetterPlayerDataSourceType.network,
            "https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4"));

    printPIPSupport();
    setState(() {});
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Theme.of(context).colorScheme.inversePrimary,
        title: Text(widget.title),
      ),
      body: Center(
        child: Column(
          children: [

            AspectRatio(
                aspectRatio: 16 / 9,
                child: BetterPlayer(
                  key: _betterPlayerKey,
                  controller: _betterPlayerController,
                )),

            ElevatedButton(
                onPressed: () {
                  setState(() {
                    _betterPlayerController
                        .enablePictureInPicture(_betterPlayerKey);
                  });
                },
                child: Text("PIP")),
            ElevatedButton(
                onPressed: () {
                 Navigator.of(context).push(MaterialPageRoute(builder: (context) => SeccondScreen(),));
                },
                child: Text("second Screen")),
          ],
        ),
      ),
    );
  }

  void printPIPSupport() async {
    print(
        "isPictureInPictureSupported ${await _betterPlayerController.isPictureInPictureSupported()}");
  }
}