title: How to play a List of video in Flutter?
body: <p>I'm using flutter <a href="https://pub.dartlang.org/packages/video_player" rel="noreferrer"><code>video_player</code></a> package to play a list of video.</p>
  
  <pre class="lang-dart prettyprint-override"><code>List sourceList;
  
  sourceList = [
    {
      "size": 69742504,
      "name": "lucky-roulette.mp4",
      "mimetype": "video/mp4",
    },
    {
      "size": 69742504,
      "name": "BigBuckBunny.mp4",
      "mimetype": "video/mp4",
    }
  ];
  </code></pre>
  
  <p>I've checked out <a href="https://github.com/flutter/flutter/issues/22015" rel="noreferrer">this issue</a>, and did some custom codes upon it.</p>
  
  <pre class="lang-dart prettyprint-override"><code>void play() {
    log.fine("Now playing: $_nowPlayingUrl");
    _adController = VideoPlayerController.network(_nowPlayingUrl);
    _adController.initialize().then((_) =&gt; setState(() {}));
    _adController.play();
    _adController.addListener(checkIfVideoFinished);
  }
  
  void checkIfVideoFinished() {
    if (_adController == null ||
        _adController.value == null ||
        _adController.value.position == null ||
        _adController.value.duration == null) return;
    if (_adController.value.position.inSeconds ==
        _adController.value.duration.inSeconds) {
      _adController.removeListener(checkIfVideoFinished);
      _adController.dispose();
      // Change _nowPlayingIndex
      setState(() {
        _nowPlayingIndex = (_nowPlayingIndex + 1) % _totalIndex;
      });
      play();
    }
  }
  </code></pre>
  
  <p>But use this code snippet would send out an exception <code>Another exception was thrown: A VideoPlayerController was used after being disposed.</code></p>
  
  <p>Is there a better way to play and loop a list of video in Flutter?</p>