react_player.py 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. """React-Player component."""
  2. from __future__ import annotations
  3. from reflex.components.component import NoSSRComponent
  4. from reflex.event import EventHandler
  5. from reflex.vars.base import Var
  6. class ReactPlayer(NoSSRComponent):
  7. """Using react-player and not implement all props and callback yet.
  8. reference: https://github.com/cookpete/react-player.
  9. """
  10. library = "react-player@2.16.0"
  11. tag = "ReactPlayer"
  12. is_default = True
  13. # The url of a video or song to play
  14. url: Var[str]
  15. # Set to true or false to pause or play the media
  16. playing: Var[bool]
  17. # Set to true or false to loop the media
  18. loop: Var[bool]
  19. # Set to true or false to display native player controls.
  20. controls: Var[bool] = True # type: ignore
  21. # Set to true to show just the video thumbnail, which loads the full player on click
  22. light: Var[bool]
  23. # Set the volume of the player, between 0 and 1
  24. volume: Var[float]
  25. # Mutes the player
  26. muted: Var[bool]
  27. # Set the width of the player: ex:640px
  28. width: Var[str]
  29. # Set the height of the player: ex:640px
  30. height: Var[str]
  31. # Called when media is loaded and ready to play. If playing is set to true, media will play immediately.
  32. on_ready: EventHandler[lambda: []]
  33. # Called when media starts playing.
  34. on_start: EventHandler[lambda: []]
  35. # Called when media starts or resumes playing after pausing or buffering.
  36. on_play: EventHandler[lambda: []]
  37. # Callback containing played and loaded progress as a fraction, and playedSeconds and loadedSeconds in seconds. eg { played: 0.12, playedSeconds: 11.3, loaded: 0.34, loadedSeconds: 16.7 }
  38. on_progress: EventHandler[lambda progress: [progress]]
  39. # Callback containing duration of the media, in seconds.
  40. on_duration: EventHandler[lambda seconds: [seconds]]
  41. # Called when media is paused.
  42. on_pause: EventHandler[lambda: []]
  43. # Called when media starts buffering.
  44. on_buffer: EventHandler[lambda: []]
  45. # Called when media has finished buffering. Works for files, YouTube and Facebook.
  46. on_buffer_end: EventHandler[lambda: []]
  47. # Called when media seeks with seconds parameter.
  48. on_seek: EventHandler[lambda seconds: [seconds]]
  49. # Called when playback rate of the player changed. Only supported by YouTube, Vimeo (if enabled), Wistia, and file paths.
  50. on_playback_rate_change: EventHandler[lambda e0: []]
  51. # Called when playback quality of the player changed. Only supported by YouTube (if enabled).
  52. on_playback_quality_change: EventHandler[lambda e0: []]
  53. # Called when media finishes playing. Does not fire when loop is set to true.
  54. on_ended: EventHandler[lambda: []]
  55. # Called when an error occurs whilst attempting to play media.
  56. on_error: EventHandler[lambda: []]
  57. # Called when user clicks the light mode preview.
  58. on_click_preview: EventHandler[lambda: []]
  59. # Called when picture-in-picture mode is enabled.
  60. on_enable_pip: EventHandler[lambda: []]
  61. # Called when picture-in-picture mode is disabled.
  62. on_disable_pip: EventHandler[lambda: []]