parseEvent method
dynamic
parseEvent(
- dynamic event
Implementation
parseEvent(dynamic event) {
try {
final data = Map<String, dynamic>.from(jsonDecode(event));
if (data.containsKey('state')) {
final state = _mapStateFromString(data['state']);
playerStateSink.add(state);
isPlaying = state == PlayerState.playing;
}
if (data.containsKey("width")) {
final width = data['width'];
final height = data['height'];
final ratio = width / height;
_aspectRatiosink.add(ratio);
playerAspectRatio.value = double.parse(ratio.toString());
}
if (data.containsKey('duration') || data.containsKey("position")) {
final duration = Duration(milliseconds: data['duration']);
final position = Duration(milliseconds: data['position']);
final bufferedPosition = Duration(milliseconds: data['buffered'] ?? 0);
durationSink.add(duration);
this.duration = duration;
positionSink.add(position);
this.position = position;
bufferSink.add(bufferedPosition);
}
if (data.containsKey('initializationEvent')) {
final initalization =
_mapInitializationEventFromString(data['initializationEvent']);
_initializationsink.add(initalization);
isInitialized = initalization == InitializationEvent.initialized;
}
} catch (e) {
log("Error: $e");
disposePlayer();
}
}