flutter 视频播放 VideoPlayController

2019独角兽企业重金招聘Python工程师标准>>> hot3.png

主要用到了 VideoPlay(VideoPlayController)

  VideoPlayerController controller;
  bool initialized = false;

  @override
  void initState() {
    super.initState();

    //初始化播放控件
    controller= VideoPlayerController.file(widget.videoFile);

   //视频初始化
    controller.initialize().then((value){
        initialized=true;
        //刷新页面显示播放器
        setState(() {
        });
    });
  }

  @override
  Widget build(BuildContext context) {
    if (initialized) {
      final Size size = controller.value.size;
      return SizedBox(width:100.0,child:AspectRatio(
          aspectRatio: size.width / size.height,
          child: VideoPlayer(controller),
        ));
    } else {
      return new Container();
    }
  }

前面需要导入

import 'package:video_player/video_player.dart';
import 'package:dio/dio.dart';

 

转载于:https://my.oschina.net/u/554046/blog/2980930

你可能感兴趣的:(flutter 视频播放 VideoPlayController)