【问题标题】:How to integrate "onprogress" function in react-azure-mp?如何在 react-azure-mp 中集成“onprogress”功能?
【发布时间】:2021-03-02 00:01:39
【问题描述】:

我有一个 React 应用来播放来自后端的一些视频。为了播放视频,我将 npm 模块 react-azure-mp 集成为 Azure 媒体播放器的包装模块。根据 Azure 媒体播放器文档,有一个名为 onprogress 的函数来调用 Xmlhttprequest。我需要在 npm 模块中调用此函数,但到目前为止我尝试的操作失败了。 视频可以正常播放基本功能,但 onprogress 功能不起作用。 这是 react-azure-mp 和我尝试过的

import { AzureMP } from 'react-azure-mp';

onProgress = () => {
    console.log("working...");
}

<AzureMP
    options={{ controls: true, autoplay: false }}
    onprogress={this.onProgress} // this is not working
    adaptRatio={[4, 3]}
    src={[{ src: video.resourceUrl }]}
/>

Azure 媒体播放器文档 - XMLHTTPRequests:https://amp.azure.net/libs/amp/latest/docs/index.html#amp.xmlhttprequestwrapper.onprogress

我该如何整合它?

【问题讨论】:

    标签: reactjs azure


    【解决方案1】:

    你能凑合一下progress 事件吗?您可以使用从onInstanceCreated 回调返回的播放器抓取它设置的播放器。

      onProgress = () => {
        //
      }
      const onInstanceCreated = (player) => {
        if (player) {
           player.on("progress", onProgress);
        }
      };
    
      return (
          <AzureMP onInstanceCreated={onInstanceCreated} />
       );
    

    samples 之一中看到了与此类似的事情

    【讨论】:

    • refplayer 对象,但是当console.log(ref.player) 时,它说undefined,因此上面的if 条件是false。这是为什么呢?
    • ref 在组件被挂载之前是未定义的。一旦可用,它应该具有正确的值。
    • 我确定播放器已安装,因为正在播放视频。那么错在哪里呢?
    • 这里是沙箱,我用来测试这个codesandbox.io/s/hungry-shannon-bx8ho?file=/src/App.js可能是不同版本的库?
    • 你可以在onProgress中使用player.currentTime()如果你把它传递给播放器player.on("progress", event =&gt; onProgress(event, player)
    猜你喜欢
    • 2020-02-24
    • 1970-01-01
    • 2020-07-15
    • 2020-12-13
    • 2019-03-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多