play method
Future
play(
{ - required String audioID,
- void progressCallBack(
- double duration,
- double position
)?,
- 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();
}
}