【问题标题】:How to show circular indicator on flutter chewie player on network loss如何在网络丢失时在颤振咀嚼播放器上显示圆形指示器
【发布时间】:2022-01-19 12:14:57
【问题描述】:

我正在做一个项目,我正在使用颤振咀嚼播放器播放视频。但是当没有网络时(或者当我关闭互联网时),它会显示错误:

VideoError, Video player had error com.google.android.exoplayer2.ExoPlaybackException: Source error, null, null

我想在网络丢失时显示一个圆形指示器,而不是这个错误,并希望在网络恢复后继续播放。如何实现?

我的咀嚼控制器如下:

    chewieController = ChewieController(
        videoPlayerController: _videoPlayerController,
        aspectRatio: 16 / 9,
        autoPlay: true,
        looping: false,
        startAt: Duration(seconds: timeWatched),
        errorBuilder: (context, errorMessage) {
          return Center(
            child: Text(
              errorMessage,
              style: TextStyle(color: Colors.white),
            ),
          );
        },
        showControls: true,
        allowFullScreen: true,
        fullScreenByDefault: false,
        customControls: CupertinoControls(
          backgroundColor: Colors.black,
          iconColor: COLORS['PRIMARY_COLOR'],
        ));```

【问题讨论】:

    标签: flutter dart flutter-video-player


    【解决方案1】:

    您可以使用 pub.dev 中的connectivity_plus 包,并监听用户设备连接的变化。

    @override
    initState() {
      super.initState();
    
      subscription = Connectivity().onConnectivityChanged.listen((ConnectivityResult result) {
        // Got a new connectivity status!
      })
    }
    

    您可以在设备连接状态发生变化时执行不同的操作。就像在状态更改为 ConnectivityResult.none 时显示 CircularProgressIndicator() 并在状态更改为 ConnectivityResult.wifiConnectivityResult.mobile 时继续播放(隐藏指示器)一样。

    别忘了处置订阅:

    @override
      void dispose() {
        subscription.cancel();
        super.dispose();
      }
    

    【讨论】:

    • 但是当连接回到视频播放器时它会恢复..并且可以隐藏错误吗?
    • 是的,上面的订阅一直在监听设备的连接,如果它发生变化,它会给你一个新的结果状态。
    猜你喜欢
    • 2021-06-08
    • 2021-06-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-10
    • 2020-12-30
    • 1970-01-01
    相关资源
    最近更新 更多