Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

video doesn't change when source is updated #17

Open
godmar opened this issue Apr 13, 2023 · 1 comment
Open

video doesn't change when source is updated #17

godmar opened this issue Apr 13, 2023 · 1 comment

Comments

@godmar
Copy link

godmar commented Apr 13, 2023

Hi, when the components source property changes, should the video that's displayed be updated?

My test case:

<script>
    import VideoPlayer from 'svelte-video-player';
    let src1 = 'https://res.cloudinary.com/dvm02rtnk/video/upload/v1628057414/blender/HERO_Blender_Grease_Pencil_Showcase_1080p_ctsjpy.mp4';
    let src2 = 'https://res.cloudinary.com/dvm02rtnk/video/upload/v1628057411/blender/Agent_327_Operation_Barbershop_1080p_hf1iq7.mp4';

    let source = "please select a video";
</script>
<h1>svelte-video-player</h1>
<div style="max-width: 40%">
    <div>
    Select
    <button on:click={() => source = src1}>Video 1</button>
    <button on:click={() => source = src2}>Video 2</button>
    </div>
    <div>
    Currently playing: {source}
    </div>
    <VideoPlayer bind:source={source} />
</div>

Pressing a button changes source, but VideoPlayer seems to want to play please select a video (if I do let source = src1 is player the first video, always.

@godmar
Copy link
Author

godmar commented Apr 13, 2023

PS: I believe that HTML5 video requires calling .load() when the sources or src changes, see HTMLMediaElement: load method.

The component as currently written doesn't appear to do this. I'm also not sure how to retrieve the <video> element from it, but here's a work around I found works:

<script>
    import VideoPlayer from 'svelte-video-player';
    let src1 = 'https://res.cloudinary.com/dvm02rtnk/video/upload/v1628057414/blender/HERO_Blender_Grease_Pencil_Showcase_1080p_ctsjpy.mp4';
    let src2 = 'https://res.cloudinary.com/dvm02rtnk/video/upload/v1628057411/blender/Agent_327_Operation_Barbershop_1080p_hf1iq7.mp4';

    let source = "please select a video";
    let player;
    function select(k) {
        source = k;
        player.querySelectorAll('video')[0].load();
    }
</script>
<h1>svelte-video-player</h1>
<div style="max-width: 40%">
    <div>
    Select
    <button on:click={() => select(src1)}>Video 1</button>
    <button on:click={() => select(src2)}>Video 2</button>
    </div>
    <div bind:this={player}>
    Currently playing: {source}
        <VideoPlayer source={source} />
    </div>
</div>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant