YoutubeVideoState.fromJson constructor

YoutubeVideoState.fromJson(
  1. String json
)

Creates a new instance of YoutubeVideoState from the given json.

Implementation

factory YoutubeVideoState.fromJson(String json) {
  final state = jsonDecode(json);
  final currentTime = state['currentTime'] as num? ?? 0;
  final loadedFraction = state['loadedFraction'] as num? ?? 0;
  final positionInMs = (currentTime * 1000).truncate();

  return YoutubeVideoState(
    position: Duration(milliseconds: positionInMs),
    loadedFraction: loadedFraction.toDouble(),
  );
}