Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
* Add `Page.pop_views_until()` to pop multiple views and return a result to the destination view ([#6326](https://github.com/flet-dev/flet/issues/6326), [#6347](https://github.com/flet-dev/flet/pull/6347)) by @brunobrown.
* Make `NavigationDrawerDestination.label` accept custom controls and add `NavigationDrawerTheme.icon_theme` ([#6379](https://github.com/flet-dev/flet/issues/6379), [#6395](https://github.com/flet-dev/flet/pull/6395)) by @ndonkoHenri.
* Add `local_position` and `global_position` to `DragTargetEvent`, deprecating `x`, `y`, and `offset` ([#6387](https://github.com/flet-dev/flet/issues/6387), [#6401](https://github.com/flet-dev/flet/pull/6401)) by @ndonkoHenri.
* Add `playlist_update` method to `Video` control for on-the-fly playlist replacement ([#6390](https://github.com/flet-dev/flet/pull/6390)) by @bl1nch.

### Improvements

Expand Down
8 changes: 8 additions & 0 deletions sdk/python/examples/controls/video/example_1/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ async def handle_remove_media(e: ft.Event[ft.Button]):
r = random.randint(0, len(video.playlist) - 1)
await video.playlist_remove(r)

async def handle_update_playlist(e: ft.Event[ft.Button]):
rl = random.sample(sample_media, 3)
await video.playlist_update(rl, video.autoplay)

async def handle_jump(e: ft.Event[ft.Button]):
await video.jump_to(0)

Expand Down Expand Up @@ -110,6 +114,10 @@ async def handle_fullscreen(e: ft.Event[ft.Button]):
ft.Button(
"Remove Random Media", on_click=handle_remove_media
),
ft.Button(
"Prepare random playlist and update",
on_click=handle_update_playlist
),
ft.Button("Enter Fullscreen", on_click=handle_fullscreen),
],
),
Expand Down
12 changes: 12 additions & 0 deletions sdk/python/packages/flet-video/src/flet_video/video.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,18 @@ async def playlist_remove(self, media_index: int):
)
self.playlist.pop(media_index)

async def playlist_update(self, playlist: list[VideoMedia], autoplay: bool = False):
"""
Updates the :attr:`playlist` with the provided `playlist`.
Optionally automatically starts playing depending on `autoplay`.
"""
await self._invoke_method(
method_name="playlist_update",
arguments={"playlist": playlist, "autoplay": autoplay},
)
self.playlist = playlist
self.autoplay = autoplay

async def is_playing(self) -> bool:
"""
Returns:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,11 @@ class _VideoControlState extends State<VideoControl> with FletStoreMixin {
final mediaIndex = parseInt(args["media_index"]);
if (mediaIndex != null) await _player.remove(mediaIndex);
break;
case "playlist_update":
final playlist = Playlist(parseVideoMedias(args["playlist"], [])!);
final autoplay = parseBool(args["autoplay"], false)!;
await _player.open(playlist, play: autoplay);
break;
case "is_playing":
return _player.state.playing;
case "is_completed":
Expand Down
Loading