video.py 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. from pathlib import Path
  2. from typing import Union
  3. from .mixins.source_element import SourceElement
  4. class Video(SourceElement, component='video.js'):
  5. SOURCE_IS_MEDIA_FILE = True
  6. def __init__(self, src: Union[str, Path], *,
  7. controls: bool = True,
  8. autoplay: bool = False,
  9. muted: bool = False,
  10. loop: bool = False,
  11. ) -> None:
  12. """Video
  13. Displays a video.
  14. :param src: URL or local file path of the video source
  15. :param controls: whether to show the video controls, like play, pause, and volume (default: `True`)
  16. :param autoplay: whether to start playing the video automatically (default: `False`)
  17. :param muted: whether the video should be initially muted (default: `False`)
  18. :param loop: whether the video should loop (default: `False`)
  19. See `here <https://developer.mozilla.org/en-US/docs/Web/HTML/Element/video#events>`_
  20. for a list of events you can subscribe to using the generic event subscription `on()`.
  21. """
  22. super().__init__(source=src)
  23. self._props['controls'] = controls
  24. self._props['autoplay'] = autoplay
  25. self._props['muted'] = muted
  26. self._props['loop'] = loop
  27. def set_source(self, source: Union[str, Path]) -> None:
  28. return super().set_source(source)
  29. def seek(self, seconds: float) -> None:
  30. """Seek to a specific position in the video.
  31. :param seconds: the position in seconds
  32. """
  33. self.run_method('seek', seconds)
  34. def play(self) -> None:
  35. """Play video."""
  36. self.run_method('play')
  37. def pause(self) -> None:
  38. """Pause video."""
  39. self.run_method('pause')