audio function

Component audio(
  1. List<Component> children, {
  2. bool? autoplay,
  3. bool? controls,
  4. CrossOrigin? crossOrigin,
  5. bool? loop,
  6. bool? muted,
  7. Preload? preload,
  8. String? src,
  9. Key? key,
  10. String? id,
  11. String? classes,
  12. Styles? styles,
  13. Map<String, String>? attributes,
  14. Map<String, EventCallback>? events,
})

The <audio> HTML element is used to embed sound content in documents. It may contain one or more audio sources, represented using the src attribute or the <source> element: the browser will choose the most suitable one. It can also be the destination for streamed media, using a MediaStream.

  • autoplay: A Boolean attribute: if specified, the audio will automatically begin playback as soon as it can do so, without waiting for the entire audio file to finish downloading.
  • controls: If this attribute is present, the browser will offer controls to allow the user to control audio playback, including volume, seeking, and pause/resume playback.
  • crossOrigin: Indicates whether to use CORS to fetch the related audio file.
  • loop: If specified, the audio player will automatically seek back to the start upon reaching the end of the audio.
  • muted: Indicates whether the audio will be initially silenced. Its default value is false.
  • preload: Provides a hint to the browser about what the author thinks will lead to the best user experience.
  • src: The URL of the audio to embed. This is subject to HTTP access controls. This is optional; you may instead use the <source> element within the audio block to specify the audio to embed.

Implementation

Component audio(List<Component> children,
    {bool? autoplay,
    bool? controls,
    CrossOrigin? crossOrigin,
    bool? loop,
    bool? muted,
    Preload? preload,
    String? src,
    Key? key,
    String? id,
    String? classes,
    Styles? styles,
    Map<String, String>? attributes,
    Map<String, EventCallback>? events}) {
  return DomComponent(
    tag: 'audio',
    key: key,
    id: id,
    classes: classes,
    styles: styles,
    attributes: {
      ...attributes ?? {},
      if (autoplay == true) 'autoplay': '',
      if (controls == true) 'controls': '',
      if (crossOrigin != null) 'crossorigin': crossOrigin.value,
      if (loop == true) 'loop': '',
      if (muted == true) 'muted': '',
      if (preload != null) 'preload': preload.value,
      if (src != null) 'src': src,
    },
    events: events,
    children: children,
  );
}