-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNiceGUI_flexible_video_player.py
More file actions
42 lines (34 loc) · 1.2 KB
/
NiceGUI_flexible_video_player.py
File metadata and controls
42 lines (34 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# Example of a video player that automatically adjusts to
# the height and width of the window (viewport) when running
# a NiceGUI app in desktop (native) mode or in a browser. The
# video player always shows the video at its maximum size
# while never cutting off either the bottom or right side of
# the video.
from nicegui import ui, context
# Let the content of the current client grow to 100% view
# height (100vh). This turns an infinitely scrolling webpage
# into a single screen only. Based on this comment by Falko-s:
# www.reddit.com/r/nicegui/comments/17wl8ar/
context.get_client().content.classes('h-[100vh]')
# Add CSS for the div surrounding the video player and the
# video player itself. CSS based on the following post by ADTC.
# https://stackoverflow.com/a/77748185
ui.add_head_html('''
<style>
.video_container {
position: relative;
width: 100%;
height: 100%;
}
.video {
position: absolute;
width: 100%;
height: 100%;
object-fit: contain;
}
</style>
''')
# ui.row acts as the div to which the custom CSS is applied.
with ui.row().classes('video_container'):
v = ui.video(src='video.mp4').classes('video')
ui.run(native=True, fullscreen=False)