Skip to content

Commit

Permalink
Recreate <video> element on source urls change (#23)
Browse files Browse the repository at this point in the history
* Recreate <video> element on source urls change

* fix lint
  • Loading branch information
nklhtv authored Apr 3, 2024
1 parent 7a024f1 commit 8ab9c12
Showing 1 changed file with 27 additions and 25 deletions.
52 changes: 27 additions & 25 deletions src/components/MediaElement.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -293,31 +293,33 @@
{#if content.length > 0}
<div class="media-element {position}" class:animating={timeout} class:behind-static={videoBehindStatic || videoBehindStaticWidget} class:behind-sliding-widget={videoBehindSlidingWidget} class:headless={!showUserInterface} {style}>
<div class="inner">
<!-- svelte-ignore a11y-media-has-caption -->
<video bind:this={video}
bind:duration
bind:currentTime={time}
bind:playbackRate
preload="metadata"
playsinline
disablepictureinpicture
on:play={handlePlay}
on:pause={handlePause}
on:ended={handleEnded}
on:playing={handlePlaying}
on:durationchange={handleDurationChange}
on:loadedmetadata={handleLoadedMetadata}
on:loadeddata={handleLoadedData}
on:timeupdate={handleTimeUpdate}
on:seeked={handleSeeked}
on:ratechange={handleRateChange}>
{#if hls !== "pending" && !window.disableMediaLoad}
{#each sources as { url, contentType, format }, i}
<source src={`${url}${timeFragment(isFirstLoad, initialTime, format)}`} type={contentType} on:error={handleSourceError(i)}>
{/each}
{/if}
</video>
{#key sources.map(({ url }) => url).join("")}
<!-- svelte-ignore a11y-media-has-caption -->
<video bind:this={video}
bind:duration
bind:currentTime={time}
bind:playbackRate
preload="metadata"
playsinline
disablepictureinpicture
on:play={handlePlay}
on:pause={handlePause}
on:ended={handleEnded}
on:playing={handlePlaying}
on:durationchange={handleDurationChange}
on:loadedmetadata={handleLoadedMetadata}
on:loadeddata={handleLoadedData}
on:timeupdate={handleTimeUpdate}
on:seeked={handleSeeked}
on:ratechange={handleRateChange}>
{#if hls !== "pending" && !window.disableMediaLoad}
{#each sources as { url, contentType, format }, i}
<source src={`${url}${timeFragment(isFirstLoad, initialTime, format)}`} type={contentType} on:error={handleSourceError(i)}>
{/each}
{/if}
</video>
{/key}
{#if vastUrl || preloadVastUrl}
{#key vastUrl || preloadVastUrl}
Expand Down

0 comments on commit 8ab9c12

Please sign in to comment.