open method
Future<void>
open({
- required String path,
- required String audioType,
- String? package,
- bool autoStart = false,
- double volume = 1,
- double? seek,
- double? playSpeed,
- Map? networkHeaders,
override
Implementation
@override
Future<void> open({
required String path,
required String audioType,
String? package,
bool autoStart = false,
double volume = 1,
double? seek,
double? playSpeed,
Map? networkHeaders,
}) async {
stop();
_durationMs = null;
_position = null;
_audioElement = html.AudioElement(findAssetPath(
path,
audioType,
package: package,
));
// it seems html audielement cannot take networkHeaders :'(
_onEndListener = _audioElement?.onEnded.listen((event) {
channel.invokeMethod(WebPlayer.methodFinished, true);
});
_onCanPlayListener = _audioElement?.onCanPlay.listen((event) {
if (autoStart) {
play();
}
this.volume = volume;
final durationMs = (_audioElement?.duration ?? 0) * 1000;
if (durationMs != _durationMs) {
_durationMs = durationMs;
channel.invokeMethod(WebPlayer.methodCurrent, {'totalDurationMs': durationMs});
}
if (seek != null) {
this.seek(to: seek);
}
if (playSpeed != null) {
this.playSpeed = playSpeed;
}
// single event
_onCanPlayListener?.cancel();
_onCanPlayListener = null;
});
}