enter image description here

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,
              ),
            ),



          ],
        ),
      )
    );
  }
}

In 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 second video player primarily utilizes 'PlatformView' to play the video. On Android, it employs ExoPlayer. This code highlights an issue I'm encountering with 'PlatformView' on Android (not tested on iOS).

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. This problem also occurs with other video players in Flutter when using 'PlatformView'. In my case, I am developing a video editor with the Android based video editor API, which uses 'PlatformView' to display the video view.

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.

Is it possible in Flutter's 'PlatformView' to maintain the state of the video player during size changes?.Can anyone help me?

0

There are 0 answers