video.py 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import warnings
  2. from pathlib import Path
  3. from typing import Union
  4. from .. import globals
  5. from ..element import Element
  6. class Video(Element, component='video.js'):
  7. def __init__(self, src: Union[str, Path], *,
  8. controls: bool = True,
  9. autoplay: bool = False,
  10. muted: bool = False,
  11. loop: bool = False,
  12. type: str = '', # DEPRECATED
  13. ) -> None:
  14. """Video
  15. :param src: URL or local file path of the video source
  16. :param controls: whether to show the video controls, like play, pause, and volume (default: `True`)
  17. :param autoplay: whether to start playing the video automatically (default: `False`)
  18. :param muted: whether the video should be initially muted (default: `False`)
  19. :param loop: whether the video should loop (default: `False`)
  20. See `here <https://developer.mozilla.org/en-US/docs/Web/HTML/Element/video#events>`_
  21. for a list of events you can subscribe to using the generic event subscription `on()`.
  22. """
  23. super().__init__()
  24. if Path(src).is_file():
  25. src = globals.app.add_media_file(local_file=src)
  26. self._props['src'] = src
  27. self._props['controls'] = controls
  28. self._props['autoplay'] = autoplay
  29. self._props['muted'] = muted
  30. self._props['loop'] = loop
  31. if type:
  32. url = f'https://github.com/zauberzeug/nicegui/pull/624'
  33. warnings.warn(DeprecationWarning(f'The type parameter for ui.video is deprecated and ineffective ({url}).'))
  34. def seek(self, seconds: float) -> None:
  35. """Seek to a specific position in the video.
  36. :param seconds: the position in seconds
  37. """
  38. self.run_method('seek', seconds)