flutter chewie切换视频_flutter 实现一个页面播放不同视频

发布于 18 天前 作者 phonegap100 54 次浏览 来自 分享

flutter 如何实现一个页面播放不同视频呢?下面给大家看看flutter chewie切换视频。

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

class ChewieVideoDemo extends StatefulWidget {
  ChewieVideoDemo({Key key}) : super(key: key);

  _ChewieVideoDemoState createState() => _ChewieVideoDemoState();
}

class _ChewieVideoDemoState extends State<ChewieVideoDemo> {
  VideoPlayerController videoPlayerController;
  ChewieController chewieController;

  @override
  void initState() {
    // TODO: implement initState
    super.initState();

    videoPlayerController = VideoPlayerController.network(
        'http://vfx.mtime.cn/Video/2019/02/04/mp4/190204084208765161.mp4');

    chewieController = ChewieController(
      videoPlayerController: videoPlayerController,
      aspectRatio: 3 / 2,
      autoPlay: true,
      looping: true,
    );
  }

  /*销毁*/
  @override
  void dispose() {
    print('dispose');
    videoPlayerController.dispose();
    chewieController.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('在线视频播放'),
      ),
      body: Center(
          child: Column(
        children: <Widget>[
          Chewie(
            controller: chewieController,
          ),
          RaisedButton(
            child: Text("切换视频"),
            onPressed: () {
              videoPlayerController.pause();   
              setState(() {                           

                videoPlayerController = VideoPlayerController.network(
                    'http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4');
                chewieController = ChewieController(
                  videoPlayerController: videoPlayerController,
                  aspectRatio: 3 / 2,
                  autoPlay: true,
                  looping: true,
                );
              });
            },
          )
        ],
      )),
    );
  }
}

回到顶部