play method

Future play({
  1. required String audioID,
  2. void progressCallBack(
    1. double duration,
    2. double position
    )?,
  3. void finishCallBack()?,
})

Implementation

Future play({required String audioID, void Function(double duration, double position)? progressCallBack, void Function()? finishCallBack}) async {
  if (isPlaying) {
    await end();
  }
  if (!_recordMap.keys.contains(audioID)) {
    throw Exception(['did not register this audioID']);
  }

  if (_delegate == null) {
    throw Exception(["did not execute init()"]);
  }

  final url = _recordMap[audioID] ?? "";
  final result = await _delegate!.play(url, (duration, position) {
    /// 进度回调
    progressCallBack?.call(duration, position);
    this.duration = duration;
    this.position = position;
    notifyListeners();
  }, () async {
    await end();
    finishCallBack?.call();
  });
  if (result) {
    isPlaying = true;
    isPause = false;
    currentPlayingAudioID = audioID;
    notifyListeners();
  }
}