Flutter Video Player – AndroidCoding.in

Flutter Video Player :

 

In this blog we are going to learn the easiest way to implement video player in your flutter app. Creating a custom widget class as adding required features.

 

pubspec.yaml :

dependencies:
  flutter:
    sdk: flutter

  cupertino_icons: ^1.0.2
  chewie: ^1.3.6
  video_player: 2.4.8

 

VideoPlayerWidget.dart :

Complete code for video player widget class.

 

import 'package:chewie/chewie.dart';
import 'package:flutter/material.dart';
import 'package:video_player/video_player.dart';

class VideoPlayerWidget extends StatefulWidget 

  final VideoPlayerController videoPlayerController;
  final bool looping;
  final bool autoplay;

  VideoPlayerWidget(
      this.videoPlayerController,
      this.looping,
      this.autoplay
      );

  @override
  State<VideoPlayerWidget> createState() => _VideoPlayerWidgetState();


class _VideoPlayerWidgetState extends State<VideoPlayerWidget> 

  late ChewieController chewieController;

  @override
  void initState() 
    // TODO: implement initState
    super.initState();
    chewieController = ChewieController(videoPlayerController: widget.videoPlayerController,
      aspectRatio: 4/9,
      autoInitialize: true,
      autoPlay: widget.autoplay,
      looping: widget.looping,

      errorBuilder: (context, errorMessage)
      return Center(
        child: Text("Something went wrong"),
      );
      
    );
  

  @override
  void dispose() 
    // TODO: implement dispose
    super.dispose();
    chewieController.dispose();
  

  @override
  Widget build(BuildContext context) 
    return Container(
      child: Chewie(
        controller: chewieController,
      ),
    );
  

 

Next Post

Queens invites businesses to incubators in a bid to grow its tech industry

The 3D App and DevJee, Inc., both property-technology firms, said that participating in the Rockaways incubator would give them a deeper connection to Queens as they grow. “I live in Rockaway, and my kids go to school here,” said Kathirvel Kumararaja, president of DevJee, founded in 2015. “To see tech […]
Queens invites businesses to incubators in a bid to grow its tech industry

You May Like