audio.py 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import warnings
  2. from pathlib import Path
  3. from ..dependencies import register_vue_component
  4. from ..element import Element
  5. register_vue_component(name='audio', path=Path(__file__).parent.joinpath('audio.js'))
  6. class Audio(Element):
  7. def __init__(self, src: str, *,
  8. controls: bool = True,
  9. autoplay: bool = False,
  10. muted: bool = False,
  11. loop: bool = False,
  12. type: str = '', # DEPRECATED
  13. ) -> None:
  14. """Audio
  15. :param src: URL of the audio source
  16. :param controls: whether to show the audio controls, like play, pause, and volume (default: `True`)
  17. :param autoplay: whether to start playing the audio automatically (default: `False`)
  18. :param muted: whether the audio should be initially muted (default: `False`)
  19. :param loop: whether the audio should loop (default: `False`)
  20. See `here <https://developer.mozilla.org/en-US/docs/Web/HTML/Element/audio#events>`_
  21. for a list of events you can subscribe to using the generic event subscription `on()`.
  22. """
  23. super().__init__('audio')
  24. self._props['src'] = src
  25. self._props['controls'] = controls
  26. self._props['autoplay'] = autoplay
  27. self._props['muted'] = muted
  28. self._props['loop'] = loop
  29. self.use_component('audio')
  30. if type:
  31. url = f'https://github.com/zauberzeug/nicegui/pull/624'
  32. warnings.warn(DeprecationWarning(f'The type parameter for ui.audio is deprecated and ineffective ({url}).'))