muxinc / elements

Custom elements for working with media in the browser that Just Work™
https://elements-demo-nextjs.vercel.app
MIT License
266 stars 49 forks source link

Bug: Lazy loaded MuxPlayer duplicates children <track/> elements #894

Open fredrik-sogaard opened 7 months ago

fredrik-sogaard commented 7 months ago

Is there an existing issue for this?

Which Mux Elements/Packages does this apply to? Select all that apply

mux-player-react

Which browsers are you using?

Chrome

Which operating systems are you using?

macOS

Description

When using mux-player-react and adding a subtitle track as a child, the subtitle track gets duplicated:

CleanShot 2024-04-09 at 17 17 57@2x

Code structure:

import MuxPlayer from '@mux/mux-player-react';

 <MuxPlayer playbackId=...">
  <track
    kind="subtitles"
    label="Norsk"
    src="..."
    srcLang="no"
  />
</MuxPlayer>

Reduced test case

https://stackblitz.com/edit/vitejs-vite-fhn3wm?file=src%2FApp.tsx

Steps to reproduce

  1. Add a <track> as child of MuxPlayer
  2. See duplicated subtitle options.

Current Behavior

<track> children gets duplicated.

Expected Behavior

<track> children not getting duplicated.

Errors

No response

What version of the package are you using?

2.4.1

luwes commented 7 months ago

it's because Mux player automatically loads them from the m3u8. they can be removed with some API calls to the Mux video API https://docs.mux.com/api-reference#video/operation/delete-asset-track

is your intention to manually override the subtitles?

fredrik-sogaard commented 7 months ago

No, I want to add my own subtitle tracks stored elsewhere to the video player. We don't add subtitles to Mux directly.

We're using Sanity as a CMS and the Mux plugin doesn't support uploading subtitle tracks, so we want to load them in as <track> elements.

It is so close to working perfectly, except the duplicating issue.