3

我用chewie插件

我在互联网上有 5 个视频,想加载列表中的所有 5 个视频,当滚动列表以显示另一个视频时,首先我想停止最后一个视频,

换句话说,当列表视图位置改变时,播放视频停止

视频课

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

class VideoPleayre extends StatefulWidget {
  final String _videoUrl;
  VideoPleayre(this._videoUrl);
  @override
  State<StatefulWidget> createState() {
    return _VideoPleayreState();
  }
}

class _VideoPleayreState extends State<VideoPleayre> {
  VideoPlayerController _videoPlayerController;
  ChewieController _chewieController;
  @override
  void initState() {
    super.initState();
    _videoPlayerController = VideoPlayerController.network(widget._videoUrl);
    _chewieController = ChewieController(
      videoPlayerController: _videoPlayerController,
    );
  }

  @override
  void dispose() {
    _videoPlayerController.dispose();
    _chewieController.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Chewie(
      controller: _chewieController,
    );
  }
}

主类代码

 Map<String,String> MySourceList = {
      "Address1",
      "Address2",
      "Address3",
    }

NotificationListener(
          child: ListView.builder(
              controller: _controller,
              itemCount: MySourceList.length,
              itemBuilder: (context, index){
                VideoPleayre(
                  MySourceList[index],
                )
              }
          ),
          onNotification: (t) {
            if (t is ScrollEndNotification) {
              setState(() {
              });
            }
          },
        );
4

0 回答 0