|
1 | 1 | import random |
2 | 2 |
|
| 3 | +import flet as ft |
3 | 4 | import flet_video as ftv |
4 | 5 |
|
5 | | -import flet as ft |
| 6 | +sample_media = [ |
| 7 | + ftv.VideoMedia( |
| 8 | + "https://user-images.githubusercontent.com/28951144/229373720-14d69157-1a56-4a78-a2f4-d7a134d7c3e9.mp4" |
| 9 | + ), |
| 10 | + ftv.VideoMedia( |
| 11 | + "https://user-images.githubusercontent.com/28951144/229373718-86ce5e1d-d195-45d5-baa6-ef94041d0b90.mp4" |
| 12 | + ), |
| 13 | + ftv.VideoMedia( |
| 14 | + "https://user-images.githubusercontent.com/28951144/229373716-76da0a4e-225a-44e4-9ee7-3e9006dbc3e3.mp4" |
| 15 | + ), |
| 16 | + ftv.VideoMedia( |
| 17 | + "https://user-images.githubusercontent.com/28951144/229373695-22f88f13-d18f-4288-9bf1-c3e078d83722.mp4" |
| 18 | + ), |
| 19 | + ftv.VideoMedia( |
| 20 | + "https://user-images.githubusercontent.com/28951144/229373709-603a7a89-2105-4e1b-a5a5-a6c3567c9a59.mp4", |
| 21 | + extras={ |
| 22 | + "artist": "Thousand Foot Krutch", |
| 23 | + "album": "The End Is Where We Begin", |
| 24 | + }, |
| 25 | + http_headers={ |
| 26 | + "Foo": "Bar", |
| 27 | + "Accept": "*/*", |
| 28 | + }, |
| 29 | + ), |
| 30 | +] |
6 | 31 |
|
7 | 32 |
|
8 | 33 | def main(page: ft.Page): |
9 | | - page.theme_mode = ft.ThemeMode.LIGHT |
10 | | - page.title = "TheEthicalVideo" |
11 | | - page.window.always_on_top = True |
12 | 34 | page.spacing = 20 |
13 | 35 | page.horizontal_alignment = ft.CrossAxisAlignment.CENTER |
14 | 36 |
|
15 | | - async def handle_pause(e): |
| 37 | + async def handle_pause(e: ft.Event[ft.Button]): |
16 | 38 | await video.pause() |
17 | | - print("Video.pause()") |
18 | 39 |
|
19 | | - async def handle_play_or_pause(e): |
| 40 | + async def handle_play_or_pause(e: ft.Event[ft.Button]): |
20 | 41 | await video.play_or_pause() |
21 | | - print("Video.play_or_pause()") |
22 | 42 |
|
23 | | - async def handle_play(e): |
| 43 | + async def handle_play(e: ft.Event[ft.Button]): |
24 | 44 | await video.play() |
25 | | - print("Video.play()") |
26 | 45 |
|
27 | | - async def handle_stop(e): |
| 46 | + async def handle_stop(e: ft.Event[ft.Button]): |
28 | 47 | await video.stop() |
29 | | - print("Video.stop()") |
30 | 48 |
|
31 | | - async def handle_next(e): |
| 49 | + async def handle_next(e: ft.Event[ft.Button]): |
32 | 50 | await video.next() |
33 | | - print("Video.next()") |
34 | 51 |
|
35 | | - async def handle_previous(e): |
| 52 | + async def handle_previous(e: ft.Event[ft.Button]): |
36 | 53 | await video.previous() |
37 | | - print("Video.previous()") |
38 | 54 |
|
39 | | - def handle_volume_change(e): |
| 55 | + def handle_volume_change(e: ft.Event[ft.Slider]): |
40 | 56 | video.volume = e.control.value |
41 | | - print(f"Video.volume = {e.control.value}") |
42 | 57 |
|
43 | | - def handle_playback_rate_change(e): |
| 58 | + def handle_playback_rate_change(e: ft.Event[ft.Slider]): |
44 | 59 | video.playback_rate = e.control.value |
45 | | - print(f"Video.playback_rate = {e.control.value}") |
46 | 60 |
|
47 | | - async def handle_seek(e): |
| 61 | + async def handle_seek(e: ft.Event[ft.Button]): |
48 | 62 | await video.seek(10000) |
49 | | - print("Video.seek(10000)") |
50 | 63 |
|
51 | | - async def handle_add_media(e): |
| 64 | + async def handle_add_media(e: ft.Event[ft.Button]): |
52 | 65 | await video.playlist_add(random.choice(sample_media)) |
53 | | - print("Video.playlist_add(random.choice(sample_media))") |
54 | 66 |
|
55 | | - async def handle_remove_media(e): |
| 67 | + async def handle_remove_media(e: ft.Event[ft.Button]): |
56 | 68 | r = random.randint(0, len(video.playlist) - 1) |
57 | 69 | await video.playlist_remove(r) |
58 | | - print(f"Popped Item at index: {r} (position {r + 1})") |
59 | 70 |
|
60 | | - async def handle_jump(e): |
61 | | - print("Video.jump_to(0)") |
| 71 | + async def handle_jump(e: ft.Event[ft.Button]): |
62 | 72 | await video.jump_to(0) |
63 | 73 |
|
64 | | - sample_media = [ |
65 | | - ftv.VideoMedia( |
66 | | - "https://user-images.githubusercontent.com/28951144/229373720-14d69157-1a56-4a78-a2f4-d7a134d7c3e9.mp4" |
67 | | - ), |
68 | | - ftv.VideoMedia( |
69 | | - "https://user-images.githubusercontent.com/28951144/229373718-86ce5e1d-d195-45d5-baa6-ef94041d0b90.mp4" |
70 | | - ), |
71 | | - ftv.VideoMedia( |
72 | | - "https://user-images.githubusercontent.com/28951144/229373716-76da0a4e-225a-44e4-9ee7-3e9006dbc3e3.mp4" |
73 | | - ), |
74 | | - ftv.VideoMedia( |
75 | | - "https://user-images.githubusercontent.com/28951144/229373695-22f88f13-d18f-4288-9bf1-c3e078d83722.mp4" |
76 | | - ), |
77 | | - ftv.VideoMedia( |
78 | | - "https://user-images.githubusercontent.com/28951144/229373709-603a7a89-2105-4e1b-a5a5-a6c3567c9a59.mp4", |
79 | | - extras={ |
80 | | - "artist": "Thousand Foot Krutch", |
81 | | - "album": "The End Is Where We Begin", |
82 | | - }, |
83 | | - http_headers={ |
84 | | - "Foo": "Bar", |
85 | | - "Accept": "*/*", |
86 | | - }, |
87 | | - ), |
88 | | - ] |
| 74 | + async def handle_fullscreen(e: ft.Event[ft.Button]): |
| 75 | + video.fullscreen = True |
89 | 76 |
|
90 | 77 | page.add( |
91 | | - video := ftv.Video( |
| 78 | + ft.SafeArea( |
92 | 79 | expand=True, |
93 | | - playlist=sample_media[0:2], |
94 | | - playlist_mode=ftv.PlaylistMode.LOOP, |
95 | | - fill_color=ft.Colors.BLUE_400, |
96 | | - aspect_ratio=16 / 9, |
97 | | - volume=100, |
98 | | - autoplay=False, |
99 | | - filter_quality=ft.FilterQuality.HIGH, |
100 | | - muted=False, |
101 | | - on_load=lambda e: print("Video loaded successfully!"), |
102 | | - on_enter_fullscreen=lambda e: print("Video entered fullscreen!"), |
103 | | - on_exit_fullscreen=lambda e: print("Video exited fullscreen!"), |
104 | | - ), |
105 | | - ft.Row( |
106 | | - wrap=True, |
107 | | - alignment=ft.MainAxisAlignment.CENTER, |
108 | | - controls=[ |
109 | | - ft.Button("Play", on_click=handle_play), |
110 | | - ft.Button("Pause", on_click=handle_pause), |
111 | | - ft.Button("Play Or Pause", on_click=handle_play_or_pause), |
112 | | - ft.Button("Stop", on_click=handle_stop), |
113 | | - ft.Button("Next", on_click=handle_next), |
114 | | - ft.Button("Previous", on_click=handle_previous), |
115 | | - ft.Button("Seek s=10", on_click=handle_seek), |
116 | | - ft.Button("Jump to first Media", on_click=handle_jump), |
117 | | - ft.Button("Add Random Media", on_click=handle_add_media), |
118 | | - ft.Button("Remove Random Media", on_click=handle_remove_media), |
119 | | - ], |
120 | | - ), |
121 | | - ft.Slider( |
122 | | - min=0, |
123 | | - value=100, |
124 | | - max=100, |
125 | | - label="Volume = {value}%", |
126 | | - divisions=10, |
127 | | - width=400, |
128 | | - on_change=handle_volume_change, |
129 | | - ), |
130 | | - ft.Slider( |
131 | | - min=1, |
132 | | - value=1, |
133 | | - max=3, |
134 | | - label="PlaybackRate = {value}X", |
135 | | - divisions=6, |
136 | | - width=400, |
137 | | - on_change=handle_playback_rate_change, |
138 | | - ), |
| 80 | + content=ft.Column( |
| 81 | + expand=True, |
| 82 | + controls=[ |
| 83 | + video := ftv.Video( |
| 84 | + expand=True, |
| 85 | + playlist=sample_media[0:2], |
| 86 | + playlist_mode=ftv.PlaylistMode.LOOP, |
| 87 | + fill_color=ft.Colors.BLUE_400, |
| 88 | + aspect_ratio=16 / 9, |
| 89 | + volume=100, |
| 90 | + autoplay=False, |
| 91 | + filter_quality=ft.FilterQuality.HIGH, |
| 92 | + muted=False, |
| 93 | + on_load=lambda e: print("Video loaded successfully!"), |
| 94 | + on_enter_fullscreen=lambda e: print("Entered fullscreen!"), |
| 95 | + on_exit_fullscreen=lambda e: print("Exited fullscreen!"), |
| 96 | + ), |
| 97 | + ft.Row( |
| 98 | + wrap=True, |
| 99 | + alignment=ft.MainAxisAlignment.CENTER, |
| 100 | + controls=[ |
| 101 | + ft.Button("Play", on_click=handle_play), |
| 102 | + ft.Button("Pause", on_click=handle_pause), |
| 103 | + ft.Button("Play Or Pause", on_click=handle_play_or_pause), |
| 104 | + ft.Button("Stop", on_click=handle_stop), |
| 105 | + ft.Button("Next", on_click=handle_next), |
| 106 | + ft.Button("Previous", on_click=handle_previous), |
| 107 | + ft.Button("Seek s=10", on_click=handle_seek), |
| 108 | + ft.Button("Jump to first Media", on_click=handle_jump), |
| 109 | + ft.Button("Add Random Media", on_click=handle_add_media), |
| 110 | + ft.Button( |
| 111 | + "Remove Random Media", on_click=handle_remove_media |
| 112 | + ), |
| 113 | + ft.Button("Enter Fullscreen", on_click=handle_fullscreen), |
| 114 | + ], |
| 115 | + ), |
| 116 | + ft.Slider( |
| 117 | + min=0, |
| 118 | + value=100, |
| 119 | + max=100, |
| 120 | + label="Volume = {value}%", |
| 121 | + divisions=10, |
| 122 | + width=400, |
| 123 | + on_change=handle_volume_change, |
| 124 | + ), |
| 125 | + ft.Slider( |
| 126 | + min=1, |
| 127 | + value=1, |
| 128 | + max=3, |
| 129 | + label="Playback rate = {value}X", |
| 130 | + divisions=6, |
| 131 | + width=400, |
| 132 | + on_change=handle_playback_rate_change, |
| 133 | + ), |
| 134 | + ], |
| 135 | + ), |
| 136 | + ) |
139 | 137 | ) |
140 | 138 |
|
141 | 139 |
|
|
0 commit comments