react_player.py 3.5 KB

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