playNextVideo method

Future<void> playNextVideo()

Implementation

Future<void> playNextVideo() {
  _checkDisposed();
  try {
    if (_playlist == null) {
      throw StateError('No playlist is currently loaded');
    }

    final playlist = _player.state.playlist;
    if (playlist.medias.isEmpty) {
      throw StateError('Playlist is empty');
    }

    final currentIndex = _player.state.playlist.index;
    final nextIndex = currentIndex + 1;

    if (nextIndex < playlist.medias.length) {
      _currentPlaylistIndex = nextIndex;
      return _player.next();
    } else {
      if (kDebugMode) {
        print('Already at the last video in playlist');
      }
      return Future.value();
    }
  } catch (e) {
    if (!_errorController.isClosed && !_isDisposed) {
      _errorController.add(e.toString());
    }
    return Future.value();
  }
}