play method

Future<String> play({
  1. int? index,
  2. bool? auto,
})

Play specified subscript audio if you want

Implementation

Future<String> play({int? index, bool? auto}) async {
  if (index != null && (index < 0 || index >= _audioList.length))
    throw "invalid index";
  _auto = auto ?? true;
  _curIndex = index ?? _curIndex;
  final random = _initRandom();
  // Do not replay the same url
  if (_info!.url != random.url) {
    stop();
    _isLoading = true;
    _initialize = true;
  }
  _info = random;
  _onEvents(AudioManagerEvents.start, _info);

  final regx = new RegExp(r'^(http|https|file):\/\/\/?([\w.]+\/?)\S*');
  final result = await _channel.invokeMethod('start', {
    "url": _info!.url,
    "title": _info!.title,
    "desc": _info!.desc,
    "cover": _info!.coverUrl,
    "isAuto": _auto,
    "isLocal": !regx.hasMatch(_info!.url),
    "isLocalCover": !regx.hasMatch(_info!.coverUrl),
  });
  return result;
}