【问题标题】:How to Make Shaka Player Compatible with react Native?如何使 Shaka Player 与 react Native 兼容?
【发布时间】:2021-09-22 04:49:21
【问题描述】:

我正在开发 React-Native 应用程序。我想在 react-native 中实现 shaka 播放器。 有什么解决办法吗?

【问题讨论】:

    标签: react-native mpd shaka


    【解决方案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} />
       );
    }
    

    【讨论】:

    • 它在 react 原生移动应用 IOS 和 Android 中都有效吗?请解释清楚!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-01-12
    • 1970-01-01
    • 2020-02-08
    • 1970-01-01
    • 1970-01-01
    • 2021-11-07
    • 2020-08-06
    相关资源
    最近更新 更多