Skip to content

bug: Volume settings for flet Video are not applied #6683

Description

@jjjunehkim

Duplicate Check

Describe the bug

The volume property of the flet Video control is not working correctly. This issue persists in versions prior to 0.86.0 as well as in the latest updated version: if I set the volume property and then toggle the visible property from False to True, the volume resets to the default value of 100.

This is example code where the volume property value is not working as expected.

Code sample

Code
import flet as ft
import flet_video as ftv
import asyncio
import mimetypes


stop_flag_event = asyncio.Event()


async def main(page: ft.Page):

    sample_media = []
    play_files_list = [
        "https://picsum.photos/320/200?random=1",
        "https://picsum.photos/320/200?random=2",
        "https://user-images.githubusercontent.com/28951144/229373720-14d69157-1a56-4a78-a2f4-d7a134d7c3e9.mp4",
        "https://user-images.githubusercontent.com/28951144/229373718-86ce5e1d-d195-45d5-baa6-ef94041d0b90.mp4",
    ]

    async def video_completed(e):

        print(e.data)
        

        if e.data is not True:
            return
        
        if sample_media:
            sample_media.pop()

        if video_display.playlist:
            video_display.playlist.pop()

        stop_flag_event.set()


    async def call_play_content():
            await asyncio.sleep(2)
            
            await play_content()


    async def play_content():
        while True :
            for play_file in play_files_list :

                mime_type, _ = mimetypes.guess_type(play_file)
                print(f'{play_file = }')
                print(f'{mime_type = }')
                if mime_type == None:
                    image_display.visible = True
                    video_display.visible = False
                    image_display.content.src = play_file
                    page.update()
                    await asyncio.sleep(3)
                elif mime_type.startswith('video'):
                    image_display.visible = False
                    video_display.visible = True
                    sample_media.append(ftv.VideoMedia(play_file))
                    video_display.playlist.append(sample_media[-1])
                    page.update()
                    await asyncio.sleep(0.05)
                    # await v_play()
                    await play_video()


    # async def v_play():
    #     await play_video()

    async def play_video():
        stop_flag_event.clear()

        await video_display.play()

        await stop_flag_event.wait()



    image_display = ft.Container(
        expand = True,
        alignment = ft.Alignment.CENTER,
        content= ft.Image(
                    src = "" ,
                    width = float("inf"),    
                    height = float("inf"),   
                    fit = ft.BoxFit.FILL,
        )
    )

    video_display = ftv.Video(
        # visible = False,
        expand = True,
        playlist_mode = ftv.PlaylistMode.NONE,
        fill_color = ft.Colors.BLACK_87,
        volume = 60.0,
        fit = ft.BoxFit.FILL,
        filter_quality = ft.FilterQuality.HIGH,
        # muted = False,
        on_complete = video_completed,
        on_load = lambda e: print("Video loaded successfully!"),
        on_track_change = lambda e: print(f"track_changed : {e.data}"),
        # on_position_change = lambda e: print(f"position_changed : {e.data}"),
    )



    page.add(
        ft.SafeArea(
            expand=True,
            content= ft.Container(
                content = ft.Stack(
                    controls = [
                        image_display,
                        video_display
                    ]
                )
            )
        )
    )
    # page.run_task(call_play_content)
    await call_play_content()



if __name__ == "__main__":
    ft.run(main)

To reproduce

1

Expected behavior

No response

Screenshots / Videos

Captures

[Upload media here]

Operating System

Windows

Operating system details

Windows11

Flet version

0.86.0

Regression

No, it isn't

Suggestions

No response

Logs

Logs
[Paste your logs here]

Additional details

No response

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Fields

No fields configured for issues without a type.

Projects

Status
👀 In review

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions