From 86a42376ad93af480d6fa7c8795937b484e86635 Mon Sep 17 00:00:00 2001 From: Maruf Hassan <50977126+zyllus17@users.noreply.github.com> Date: Sun, 15 Jan 2023 19:04:26 +0530 Subject: [PATCH] Updated chewie player for pub.dev Updated with a simpler example to start working with Chewie player --- example/lib/main.dart | 71 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 70 insertions(+), 1 deletion(-) diff --git a/example/lib/main.dart b/example/lib/main.dart index 000c2d096..9c0a4f05b 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -1,8 +1,77 @@ +import 'package:chewie/chewie.dart'; import 'package:chewie_example/app/app.dart'; import 'package:flutter/material.dart'; +// ignore_for_file: depend_on_referenced_packages +import 'package:video_player/video_player.dart'; void main() { runApp( - const ChewieDemo(), + const ChewieVideoPlayer(), ); } + +class ChewieVideoPlayer extends StatefulWidget { + const ChewieVideoPlayer({Key? key}) : super(key: key); + + @override + State createState() => _ChewieVideoPlayerState(); +} + +class _ChewieVideoPlayerState extends State { + TargetPlatform? _platform; + late VideoPlayerController videoPlayerController; + ChewieController? chewieController; + + @override + void initState() { + super.initState(); + initializeVideoPlayer(); + } + + Future initializeVideoPlayer() async { + videoPlayerController = VideoPlayerController.network( + "https://flutter.github.io/assets-for-api-docs/assets/videos/butterfly.mp4", + ); + + await videoPlayerController.initialize(); + + chewieController = ChewieController( + materialProgressColors: ChewieProgressColors(playedColor: Colors.blue), + videoPlayerController: videoPlayerController, + autoInitialize: true, + autoPlay: true, + looping: true, + errorBuilder: (context, errorMessage) { + return const Center( + child: CircularProgressIndicator(), + ); + }, + ); + setState(() {}); + } + + @override + Widget build(BuildContext context) { + final chewie = chewieController; + return MaterialApp( + theme: Theme.of(context).copyWith( + platform: _platform ?? Theme.of(context).platform, + ), + home: Scaffold( + appBar: AppBar( + title: const Text("ChewiePlayer"), + ), + body: Center( + child: + chewie != null && chewie.videoPlayerController.value.isInitialized + ? Chewie( + controller: chewie, + ) + : const Center( + child: CircularProgressIndicator(color: Colors.red), + ), + ), + ), + ); + } +}