Click here to Skip to main content
15,346,249 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am using a video player to play the videos I get from my streambuilder. I am unable to place my dispose function in such a way that I don't get this error.


Error is causing the emulator to crash after certain point.


My screen where I am getting this error:

class _PageViewBuilderState extends State<PageViewBuilder> {
  VideoPlayerController? INvideoPlayerController;
  @override
  void initState() {
    super.initState();
    INvideoPlayerController = VideoPlayerController.network('')
      ..addListener(() {})
      ..setLooping(true)
      ..initialize().then((value) => INvideoPlayerController!.play());
  }

  @override
  void dispose() {
    INvideoPlayerController?.dispose();
    super.dispose();
  }

  int _currentPage = 0;
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: StreamBuilder<QuerySnapshot<Map<String, dynamic>>>(
          stream:
              FirebaseFirestore.instance.collection('Videourls').snapshots(),
          builder: (ctx, snapshot) {
            if (snapshot.hasError) {
              const Center(
                child: Text('Unknown Error'),
              );
            }

            return !snapshot.hasData
                ? const Center(
                    child: CircularProgressIndicator(),
                  )
                : PageView.builder(
                    scrollDirection: Axis.vertical,
                    itemCount: snapshot.data!.docs.length,
                    onPageChanged: (int page) {
                      setState(() {
                        _currentPage = page;
                      });
                    },
                    itemBuilder: (BuildContext context, int index) {
                      INvideoPlayerController = VideoPlayerController.network(
                        snapshot.data!.docs[index].get('url'),
                      )
                        ..setLooping(true)
                        ..initialize()
                            .then((value) => INvideoPlayerController!.play());
                      return Stack(alignment: Alignment.center, children: [
                        AspectRatio(
                          aspectRatio: MediaQuery.of(context).size.width /
                              MediaQuery.of(context).size.height,
                          //  INvideoPlayerController!.value.aspectRatio,
                          child: VideoPlayer(INvideoPlayerController!),
                        ),
                        Container(),
                          ]),
                        ])
                      ]);
                    },
                  );
          }),
    );
  }
}


What I have tried:

I placed the dispose after the initialising the video player but has not worked because I am initialising the video player again.
I tried putting in build function of stream builder too but it does not work
Posted
Comments
ukicomputers.github.io 12-May-22 5:45am
   
On what device you running? Do you have a CPU or a GPU encoding. And how you much have a RAM+ROM memory?
Kavya Bhargava 13-May-22 18:38pm
   
So I am getting this device on all the android devices I ran it on

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900