albemala / native_video_player

A Flutter widget to play videos on iOS and Android using a native implementation.
MIT License
14 stars 12 forks source link

Size Change Causes Video Player to Stop Playing But video_player: ^2.8.2 works fine without any problems #16

Open linslouis opened 6 months ago

linslouis commented 6 months ago
import 'package:flutter/material.dart';
import 'package:native_video_player/native_video_player.dart';
import 'package:video_player/video_player.dart';

void main() {
  runApp(const MyApp());
}

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

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  late VideoPlayerController _controller;

  late NativeVideoPlayerController controllerPV;

  double sizedHeight=250.0;

  @override
  void initState() {
    // TODO: implement initState
    super.initState();

    _controller = VideoPlayerController.networkUrl(
      Uri.parse(
          'https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/WhatCarCanYouGetForAGrand.mp4'),

      videoPlayerOptions: VideoPlayerOptions(mixWithOthers: true),
    );

     _controller.addListener(() {
      setState(() {});
    });
    _controller.setLooping(true);
    _controller.initialize();
  }
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home:Scaffold(
        appBar: AppBar(
          title: const Text('Video Player'),
        ),
        body: Column(

          children: [
            SizedBox(
              height: sizedHeight,
              child: AspectRatio(
                aspectRatio: 16/9,

                child: VideoPlayer(
                  _controller,
                ),
              ),
            ),
            ElevatedButton(
              onPressed: () {
                setState(() {
                  if (_controller.value.isPlaying) {
                    _controller.pause();
                    controllerPV.pause();
                  } else {
                    _controller.play();
                    controllerPV.play();
                  }
                });
              },
              child: Icon(
                _controller.value.isPlaying ? Icons.pause : Icons.play_arrow,
              ),
            ),
            SizedBox(
              height: sizedHeight,
              child: AspectRatio(
                aspectRatio: 16/9,
                child: NativeVideoPlayerView(
                  onViewReady: (controller) async {
                    controllerPV=controller;
                    final videoSource = await VideoSource.init(
                      path: 'https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/WhatCarCanYouGetForAGrand.mp4',
                      type: VideoSourceType.network,
                    );
                    await controller.loadVideoSource(videoSource);

                  },
                ),

              ),
            ),

            ElevatedButton(
              onPressed: () {
                setState(() {
                  sizedHeight=220.0;
                });
              },
              child: const Icon(
               Icons.lock_reset_outlined,
              ),
            ),

          ],
        ),
      )
    );
  }
}

ezgif-3-b277a98a24

n my code, I am using two video players to play the same video simultaneously. The first one uses video_player: ^2.8.2, and the second uses native_video_player: ^1.3.1.

The issue arises when the size changes: the video_player: ^2.8.2 video continues to play without any interruptions, but the native_video_player: ^1.3.1 stops playing.

Here is a simplified representation of my issue. I've added a button in my code to change the size of the video player to emulate the size change scenario.