• flutter chewie 视频播放


    1.下载插件

    chewie: ^0.9.8+1
    video_player: ^0.10.10

    2.在使用页面引入

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

     3.定义

      VideoPlayerController videoPlayerController;
      ChewieController chewieController;

    4.初始化在 initState() 中

        videoPlayerController = VideoPlayerController.network(
            'https://www.runoob.com/try/demo_source/mov_bbb.mp4');
        
        videoPlayerController.initialize(); // 初始化
        
        chewieController = ChewieController(
          videoPlayerController: videoPlayerController,
          aspectRatio: 3 / 2, //宽高比
          autoPlay: false, //自动播放
          looping: false, //循环播放
        );

    5.在 dispose()中卸载

    videoPlayerController.dispose();

    6.使用

    Container(
                        height: 200,
                        child: Chewie(
                            controller: ChewieController(
                                videoPlayerController:videoPlayerController
                            )
                        ),
                      )

    6.成功啦

    如果想获取请求的视频链接,那就在builder里初始化,这样的话就可以删掉initState() 中的初始化设置,就是第三步不要

       // 判断视频是否存在
        if(data["videoUrl"] != null ) {
          videoPlayerController = VideoPlayerController.network(
              data["videoUrl"]
          );
          videoPlayerController.initialize(); // 初始化
    
          chewieController = ChewieController(
            videoPlayerController: videoPlayerController,
    //        aspectRatio: 3 / 2, //宽高比
            autoPlay: false, //自动播放
            looping: false, //循环播放
          );
        }

     

  • 相关阅读:
    反射:框架设计的灵魂
    Junit测试
    XML笔记
    map 的用法
    opencv总结1
    光源
    镜面反射
    openGL纹理对象
    GPU入门
    动态规划1
  • 原文地址:https://www.cnblogs.com/lude1994/p/14255273.html
Copyright © 2020-2023  润新知