Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/dart/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Flutter 在列表视图中使用CachedVideoPlayer_Flutter_Dart_Flutter Video Player - Fatal编程技术网

Flutter 在列表视图中使用CachedVideoPlayer

Flutter 在列表视图中使用CachedVideoPlayer,flutter,dart,flutter-video-player,Flutter,Dart,Flutter Video Player,我试图在列表视图中显示视频,这会阻止我在initState中声明videocontroller。这导致我在应用程序中意外地多次重画视频。我收到这个错误: FATAL EXCEPTION: ExoPlayerImplInternal:Handler 然后 使用我当前的实现。它似乎可以工作一段时间,但记忆会慢慢积累,直到填满为止。我如何以不同的方式实现这一点 以下是我在流中调用的代码: Widget getVideoItem(DocumentSnapshot doc) { if (wat

我试图在
列表视图中显示视频,这会阻止我在
initState
中声明
videocontroller
。这导致我在应用程序中意外地多次重画视频。我收到这个错误:

FATAL EXCEPTION: ExoPlayerImplInternal:Handler
然后

使用我当前的实现。它似乎可以工作一段时间,但记忆会慢慢积累,直到填满为止。我如何以不同的方式实现这一点

以下是我在流中调用的代码:

 Widget getVideoItem(DocumentSnapshot doc) {
    if (watchList.contains(doc['user'])) watched = true;
    DateTime dateTime = DateTime.parse(doc['time']);

    _videoPlayerController = CachedVideoPlayerController.network(doc["downUrl"])
      ..initialize();
    _videoPlayerController.setLooping(true);
    _videoPlayerController.play();

    volumeOn = sharedPreferences.getBool("vidVol");
    if (volumeOn == null) {
      sharedPreferences.setBool("vidVol", false);
      volumeOn = false;
    }

    if (volumeOn) {
      _videoPlayerController.setVolume(1.0);
    } else {
      _videoPlayerController.setVolume(0.0);
    }

    return new FutureBuilder(
      future: getUserData(doc["user"]),
      builder: (BuildContext context, snapshot) {
        return SizedBox(
          height: MediaQuery.of(context).size.width + 140,
          width: MediaQuery.of(context).size.width,
          child: Column(children: <Widget>[
            new ListTile(
              title: new Text(userInfo),
              subtitle: new Text(doc["title"]),
              leading: FutureBuilder(
                  future: getProfUrl(doc),
                  builder: (BuildContext context, snapshot) {
                    Widget child;
                    if (!snapshot.hasData) {
                      child = _showCircularProgress();
                    } else {
                      child = child = new Container(
                        width: 44.0,
                        height: 44.0,
                        child: CachedNetworkImage(
                          imageUrl: doc["profUrl"],
                          imageBuilder: (context, imageProvider) => Container(
                            decoration: BoxDecoration(
                              shape: BoxShape.circle,
                              image: DecorationImage(
                                image: imageProvider,
                                fit: BoxFit.cover,
                              ),
                            ),
                          ),
                        ),
                      );
                    }
                    return child;
                  }),
            ),
            new Padding(
              padding: EdgeInsets.fromLTRB(4, 4, 4, 4),
              child: FutureBuilder(
                  future: getDownUrl(doc),
                  builder: (BuildContext context, snapshot) {
                    List<Widget> children;
                    if (!snapshot.hasData) {
                      children = [_showCircularProgress()];
                    } else {
                      children = [
                        Center(
                          child: new AspectRatio(
                            aspectRatio: 1 / 1,
                            child: Stack(
                              children: [
                                VisibilityDetector(
                                    key: Key("unique key"),
                                    onVisibilityChanged: (VisibilityInfo info) {
                                      if (info.visibleFraction > .20) {
                                        _videoPlayerController.pause();
                                      } else {
                                        _videoPlayerController.play();
                                      }
                                    },
                                    child: CachedVideoPlayer(
                                      _videoPlayerController,
                                    )),
                                IconButton(
                                  icon: volumeOn
                                      ? Icon(Icons.volume_up)
                                      : Icon(Icons.volume_off),
                                  onPressed: () {
                                    setState(() {
                                      _videoPlayerController.pause();
                                      sharedPreferences.setBool(
                                          "vidVol", !volumeOn);
                                    });
                                  },
                                ),
                              ],
                            ),
                          ),
                        )
                      ];
                    }

                    return Center(
                      child: Column(
                        mainAxisAlignment: MainAxisAlignment.center,
                        crossAxisAlignment: CrossAxisAlignment.center,
                        children: children,
                      ),
                    );
                  }),
            ),
            new Row(
              children: [
                new IconButton(
                    icon: !watched
                        ? new Icon(
                            Icons.remove_red_eye,
                            color: Colors.black26,
                          )
                        : new Icon(
                            Icons.remove_red_eye,
                            color: Colors.blueGrey[400],
                          ),
                    onPressed: () {
                      initToggleWatched(watchList, doc["user"], name, position,
                          secPosition, state, year, user);
                    }),
                Padding(
                  padding: EdgeInsets.fromLTRB(5, 0, 0, 0),
                  child: Align(
                    alignment: Alignment.centerLeft,
                    child: Text(
                      dateTime.day.toString() +
                          "/" +
                          dateTime.month.toString() +
                          "/" +
                          dateTime.year.toString(),
                      style: TextStyle(color: Colors.black26, fontSize: 12),
                    ),
                  ),
                ),
              ],
            )
          ]),
        );
      },
    );
  }
小部件getVideoItem(文档快照文档){ if(watchList.contains(doc['user'])watched=true; DateTime DateTime=DateTime.parse(doc['time']); _videoPlayerController=CachedVideoPlayerController.network(doc[“downUrl”]) ..初始化(); _videoPlayerController.setLooping(真); _videoPlayerController.play(); volumeOn=SharedReferences.getBool(“vidVol”); if(volumeOn==null){ setBool(“vidVol”,false); volumeOn=false; } 如果(卷){ _videoPlayerController.setVolume(1.0); }否则{ _videoPlayerController.setVolume(0.0); } 返回新的FutureBuilder( 未来:getUserData(文档[“用户]), 生成器:(BuildContext上下文,快照){ 返回大小框( 高度:MediaQuery.of(上下文).size.width+140, 宽度:MediaQuery.of(context).size.width, 子项:列(子项:[ 新ListTile( 标题:新文本(用户信息), 副标题:新文本(文件[“标题]), 主角:未来建设者( 未来:getProfUrl(文档), 生成器:(BuildContext上下文,快照){ 小部件儿童; 如果(!snapshot.hasData){ child=_showCircularProgress(); }否则{ 子容器=子容器=新容器( 宽度:44.0, 身高:44.0, 子:CachedNetworkImage( imageUrl:doc[“profull”], imageBuilder:(上下文,imageProvider)=>容器( 装饰:盒子装饰( 形状:BoxShape.circle, 图像:装饰图像( 图片:imageProvider, 适合:BoxFit.cover, ), ), ), ), ); } 返回儿童; }), ), 新填料( 填充:从LTRB(4,4,4,4)开始的边缘设置, 孩子:未来建设者( 未来:getDownUrl(文档), 生成器:(BuildContext上下文,快照){ 列出儿童名单; 如果(!snapshot.hasData){ children=[[u showCircularProgress()]; }否则{ 儿童=[ 居中( 孩子:新的方面( 方面:1/1, 子:堆栈( 儿童:[ 可视性检测器( 密钥:密钥(“唯一密钥”), onVisibilityChanged:(VisibilityInfo信息){ 如果(info.visibleFraction>0.20){ _videoPlayerController.pause(); }否则{ _videoPlayerController.play(); } }, 孩子:CachedVideoPlayer( _视频播放控制器, )), 图标按钮( 图标:volumeOn ?图标(图标。音量增大) :图标(图标。音量关闭), 已按下:(){ 设置状态(){ _videoPlayerController.pause(); SharedReferences.setBool( “vidVol”,!volumeOn); }); }, ), ], ), ), ) ]; } 返回中心( 子:列( mainAxisAlignment:mainAxisAlignment.center, crossAxisAlignment:crossAxisAlignment.center, 儿童:儿童,, ), ); }), ), 新行( 儿童:[ 新图标按钮( 图标:!已观看 ?新图标( 图标。移除红色的眼睛, 颜色:颜色。黑色, ) :新图标( 图标。移除红色的眼睛, 颜色:颜色。蓝灰色[400], ), 已按下:(){ initToggleWatched(监视列表、文件[“用户”]、名称、位置、, 职位、州、年、用户); }), 填充物( 填充:从LTRB(5,0,0,0)开始的边缘设置, 子对象:对齐( 对齐:alignment.centerLe
 Widget getVideoItem(DocumentSnapshot doc) {
    if (watchList.contains(doc['user'])) watched = true;
    DateTime dateTime = DateTime.parse(doc['time']);

    _videoPlayerController = CachedVideoPlayerController.network(doc["downUrl"])
      ..initialize();
    _videoPlayerController.setLooping(true);
    _videoPlayerController.play();

    volumeOn = sharedPreferences.getBool("vidVol");
    if (volumeOn == null) {
      sharedPreferences.setBool("vidVol", false);
      volumeOn = false;
    }

    if (volumeOn) {
      _videoPlayerController.setVolume(1.0);
    } else {
      _videoPlayerController.setVolume(0.0);
    }

    return new FutureBuilder(
      future: getUserData(doc["user"]),
      builder: (BuildContext context, snapshot) {
        return SizedBox(
          height: MediaQuery.of(context).size.width + 140,
          width: MediaQuery.of(context).size.width,
          child: Column(children: <Widget>[
            new ListTile(
              title: new Text(userInfo),
              subtitle: new Text(doc["title"]),
              leading: FutureBuilder(
                  future: getProfUrl(doc),
                  builder: (BuildContext context, snapshot) {
                    Widget child;
                    if (!snapshot.hasData) {
                      child = _showCircularProgress();
                    } else {
                      child = child = new Container(
                        width: 44.0,
                        height: 44.0,
                        child: CachedNetworkImage(
                          imageUrl: doc["profUrl"],
                          imageBuilder: (context, imageProvider) => Container(
                            decoration: BoxDecoration(
                              shape: BoxShape.circle,
                              image: DecorationImage(
                                image: imageProvider,
                                fit: BoxFit.cover,
                              ),
                            ),
                          ),
                        ),
                      );
                    }
                    return child;
                  }),
            ),
            new Padding(
              padding: EdgeInsets.fromLTRB(4, 4, 4, 4),
              child: FutureBuilder(
                  future: getDownUrl(doc),
                  builder: (BuildContext context, snapshot) {
                    List<Widget> children;
                    if (!snapshot.hasData) {
                      children = [_showCircularProgress()];
                    } else {
                      children = [
                        Center(
                          child: new AspectRatio(
                            aspectRatio: 1 / 1,
                            child: Stack(
                              children: [
                                VisibilityDetector(
                                    key: Key("unique key"),
                                    onVisibilityChanged: (VisibilityInfo info) {
                                      if (info.visibleFraction > .20) {
                                        _videoPlayerController.pause();
                                      } else {
                                        _videoPlayerController.play();
                                      }
                                    },
                                    child: CachedVideoPlayer(
                                      _videoPlayerController,
                                    )),
                                IconButton(
                                  icon: volumeOn
                                      ? Icon(Icons.volume_up)
                                      : Icon(Icons.volume_off),
                                  onPressed: () {
                                    setState(() {
                                      _videoPlayerController.pause();
                                      sharedPreferences.setBool(
                                          "vidVol", !volumeOn);
                                    });
                                  },
                                ),
                              ],
                            ),
                          ),
                        )
                      ];
                    }

                    return Center(
                      child: Column(
                        mainAxisAlignment: MainAxisAlignment.center,
                        crossAxisAlignment: CrossAxisAlignment.center,
                        children: children,
                      ),
                    );
                  }),
            ),
            new Row(
              children: [
                new IconButton(
                    icon: !watched
                        ? new Icon(
                            Icons.remove_red_eye,
                            color: Colors.black26,
                          )
                        : new Icon(
                            Icons.remove_red_eye,
                            color: Colors.blueGrey[400],
                          ),
                    onPressed: () {
                      initToggleWatched(watchList, doc["user"], name, position,
                          secPosition, state, year, user);
                    }),
                Padding(
                  padding: EdgeInsets.fromLTRB(5, 0, 0, 0),
                  child: Align(
                    alignment: Alignment.centerLeft,
                    child: Text(
                      dateTime.day.toString() +
                          "/" +
                          dateTime.month.toString() +
                          "/" +
                          dateTime.year.toString(),
                      style: TextStyle(color: Colors.black26, fontSize: 12),
                    ),
                  ),
                ),
              ],
            )
          ]),
        );
      },
    );
  }