fromEventSubtitleAttrList static method

List<SubtitleAttribute> fromEventSubtitleAttrList(
  1. List? eventSubtitleAttrList
)

Parse a subtitle attribute list from the subtitle attribute list which given by eventListener.

Implementation

static List<SubtitleAttribute> fromEventSubtitleAttrList(
  List<dynamic>? eventSubtitleAttrList,
) {
  final List<SubtitleAttribute> subtitleAttributes = <SubtitleAttribute>[];
  final List<Map<Object?, Object?>?> subtitleAttrList =
      eventSubtitleAttrList!.cast<Map<Object?, Object?>?>();

  for (final Map<Object?, Object?>? attr in subtitleAttrList) {
    if (attr != null && attr['attrType'] != null) {
      final int attrTypeNum = attr['attrType']! as int;
      final int startTime = attr['startTime']! as int;
      final int stopTime = attr['stopTime']! as int;

      Object attrValue;
      if (SubtitleAttrType.getValueType(attrTypeNum) ==
          SubtitleAttrValueType.double) {
        attrValue = attr['attrValue']! as double;
      } else if (SubtitleAttrType.getValueType(attrTypeNum) ==
          SubtitleAttrValueType.int) {
        attrValue = attr['attrValue']! as int;
      } else if (SubtitleAttrType.getValueType(attrTypeNum) ==
          SubtitleAttrValueType.string) {
        attrValue = attr['attrValue']! as String;
      } else {
        attrValue = 'failed';
      }

      subtitleAttributes.add(
        SubtitleAttribute(
          attrType: SubtitleAttrType.values[attrTypeNum],
          startTime: startTime,
          stopTime: stopTime,
          attrValue: attrValue,
        ),
      );
    }
  }
  return subtitleAttributes;
}