Closed rnons closed 7 years ago
Thanks for the issue! Make sure it satisfies this checklist. My human colleagues will appreciate it!
Here is what to expect next, and if anyone wants to comment, keep these things in mind.
@rnons it seems that if you update the src
of a track
element (which is what Elm does here, as it is the minimal change required), the browser interprets that as adding a subtitle track.
The easiest fix here, is to force Elm to remove the old track
element (which removes the subtitle track entirely) and adding a fresh track
element. In order to do so, you'll want to use Html.Keyed
like so:
import Html.Keyed
view model =
div []
[ Keyed.node "video"
[ controls True ]
[ ( "video", source [ src "https://download.ted.com/talks/RandallMunroe_2014-320k.mp4" ] [] )
, ( model.selected, track [ src model.selected, default True ] [] )
]
, div []
[ button [ onClick (SelectLang "en.vtt") ] [ text "en" ]
, button [ onClick (SelectLang "zh-cn.vtt") ] [ text "zh-cn" ]
]
]
@zwilias works great, I didn't know about Html.Keyed
before. Thank you very much.
A reproducible repo: https://github.com/rnons/elm-video-track-issue
There is a video tag and two buttons. The issue is when I click button to change subtitle languages, old track is still there.