shiyiya / oplayer

:zap: Another HTM5 video player.
https://oplayer.vercel.app
MIT License
147 stars 19 forks source link

[React]Dynamic change sources of playlist plugin not working. #103

Closed leopku closed 11 months ago

leopku commented 11 months ago

Environment

"@oplayer/core": "^1.2.31",
"@oplayer/hls": "^1.2.23",
"@oplayer/plugins": "^1.0.8",
"@oplayer/react": "^1.2.9",
"@oplayer/ui": "^1.2.33",

🐛 Bug Report

Change sources of playlist plugin after an async invoking not take effect.

To Reproduce

Steps to reproduce the behavior:

const [sources, setSources] = useState();

const { data, isLoading } = useAjax({ url: 'xxxx/api' })

useEffect(() => setSources(data?.data?.playlist || []), [data])

return (
<ReactOPlayer ref={playerRef} plugins={[
  ui(),
  hls(),
  new PlaylistPlugin({
    initialIndex: 0,
    autoNext: true,
    sources,
  })
]}/>
)

After data fetched from ajax, playlist component wasn't filled in by new data.  

Expected behavior

playlist filled by data from ajax

Link to repl or repo (highly encouraged)

Please provide a minimal repository on GitHub.

Issues without a reproduction link are likely to stall.

shiyiya commented 11 months ago

use api to update source. it's not reactive

//useEffect(() => setSources(data?.data?.playlist || []), [data])
player.context.playlist.changeSourceList(list)