Falko Schindler пре 2 година
родитељ
комит
64114652ed

+ 5 - 0
nicegui/elements/video.js

@@ -1,5 +1,10 @@
 export default {
   template: `<video :controls="controls" :autoplay="autoplay" :muted="muted" :src="src" />`,
+  methods: {
+    seek(seconds) {
+      this.$el.currentTime = seconds;
+    },
+  },
   props: {
     controls: Boolean,
     autoplay: Boolean,

+ 7 - 0
nicegui/elements/video.py

@@ -36,3 +36,10 @@ class Video(Element):
         if type:
             url = f'https://github.com/zauberzeug/nicegui/pull/624'
             warnings.warn(DeprecationWarning(f'The type parameter for ui.video is deprecated and ineffective ({url}).'))
+
+    def seek(self, seconds: float) -> None:
+        """Seek to a specific position in the video.
+
+        :param seconds: the position in seconds
+        """
+        self.run_method('seek', seconds)

+ 3 - 6
website/more_documentation/video_documentation.py

@@ -9,11 +9,8 @@ def main_demo() -> None:
 
 def more() -> None:
     @text_demo('Video start position', '''
-        This demo shows how to use JavaScript to set the start position of a video.
+        This demo shows how to set the start position of a video.
     ''')
-    def advanced_usage() -> None:
-        async def set_time(_):
-            await ui.run_javascript(f'getElement({v.id}).$el.currentTime = 5;', respond=False)
-
+    def start_position_demo() -> None:
         v = ui.video('https://test-videos.co.uk/vids/bigbuckbunny/mp4/h264/360/Big_Buck_Bunny_360_10s_1MB.mp4')
-        v.on('loadedmetadata', set_time)
+        v.on('loadedmetadata', lambda: v.seek(5))