audioDuration property

Duration? get audioDuration

Duration of Section.audio, as specified in _source.metadata.

Returns null if the section has no audio version.

Implementation

Duration? get audioDuration {
  if (!hasAudio) return null;

  final durationMetadata = content.mediaOverlay!.refinements.firstWhere(
    (refinement) => refinement.property == 'media:duration',
    orElse: () => DocumentMetadata(),
  );

  if (durationMetadata.value == null) {
    throw StateError(
      '''Duration not specified in metadata
      for media overlay #${content.mediaOverlay?.id}''',
    );
  }

  return const Duration().fromString(durationMetadata.value!);
}