-2

我正在开发 React-Native 应用程序。我想在 react-native 中实现 shaka 播放器。任何解决方案?

4

1 回答 1

1

您是否尝试过使用shaka-player npm 包?你可以在你的 React 组件中使用它并实例化为状态。

import React, { useRef, useState, useEffect } from 'react';
import shaka from 'shaka-player';


const Component = () => {
   const playerRef = useRef();
   const [videoPlayer, setVideoPlayer] = useState();

   useEffect(() => {
       if (!videoPlayer) {
          const newPlayer = new shaka.Player(playerRef.current);
          setVideoPlayer(newPlayer);
          // you can start using shaka-player APIs with videoPlayer
       }
   }, []);

   return (
       <video ref={playerRef} />
   );
}
于 2021-09-22T07:54:45.897 回答