import 'package:flutter/material.dart';
import 'package:chewie/chewie.dart'; //chewie插件导入
import 'package:video_player/video_player.dart'; //video_player插件导入

class Video extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter视频播放',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home:Scaffold(
        appBar: AppBar(
          backgroundColor: Colors.white,
          title: Text('视频播放'),
          leading: GestureDetector(
            onTap: () {
              Navigator.pop(context);
            },
            child: Container(child: Icon(Icons.close,color: Colors.black)),
          ),
        ),
        body: viDeoPlayer(), //播放控件放在这里调用
      ),
    );
  }
}

//******************建议视频播放控件封装成类或函数************************
Widget viDeoPlayer() {

  var usr='http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4';  // 视频播放地址

  //视频播放控件设置
  Widget playerWidget = Chewie(
    controller: ChewieController(
      videoPlayerController: VideoPlayerController.network(usr), //播放的视频地址写在这里
      aspectRatio: 4/3, //屏幕高宽比
      autoPlay: true, //是否自动播放
      looping: false, //是否循环播放

      // fullScreenByDefault:true, //默认情况下全屏
      //isLive:true, //视频长度替换成live字样
    ),
  );
  return playerWidget; //返回
}