瀏覽代碼

Merge pull request #812 from zauberzeug/video_start

Adding demo for video start position to the docs
Falko Schindler 2 年之前
父節點
當前提交
00c237fb9b
共有 3 個文件被更改,包括 22 次插入0 次删除
  1. 5 0
      nicegui/elements/video.js
  2. 7 0
      nicegui/elements/video.py
  3. 10 0
      website/more_documentation/video_documentation.py

+ 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)

+ 10 - 0
website/more_documentation/video_documentation.py

@@ -1,6 +1,16 @@
 from nicegui import ui
+from website.documentation_tools import text_demo
 
 
 def main_demo() -> None:
     v = ui.video('https://test-videos.co.uk/vids/bigbuckbunny/mp4/h264/360/Big_Buck_Bunny_360_10s_1MB.mp4')
     v.on('ended', lambda _: ui.notify('Video playback completed'))
+
+
+def more() -> None:
+    @text_demo('Video start position', '''
+        This demo shows how to set the start position of a video.
+    ''')
+    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', lambda: v.seek(5))