简体   繁体   English

直播播放器中的自定义错误消息

[英]custom error message in player for livestream

I have a react code as shown below which renders player.我有一个如下所示的反应代码,它呈现播放器。 In the code below, if the condition is true then the code for the ReactJWPlayer is called.在下面的代码中,如果条件为真,则调用 ReactJWPlayer 的代码。

const player = ()=> {
    if(condition) {
        return (
            <ReactJWPlayer
                onPlaylist={[props.playlist]}
                onPlay={() => onPlay()}
                autoPlay={props.autoplay}
                isMuted={false}
            />
        )
    }
}

Problem Statement:问题陈述:

What I want to achieve is, I want to display a custom error message if livestream ends abruptly.我想要实现的是,如果直播突然结束,我想显示一条custom error message Right now, I am seeing:现在,我看到:

This video file cannot be played 

(Error Code: 232011)

在此处输入图片说明

I am wondering what changes I need to make in the code above so that I can replace an error message above with the following error message:我想知道我需要在上面的代码中进行哪些更改,以便我可以用以下错误消息替换上面的错误消息:

Video will be available soon . Video will be available soon

You can use onError prop to capture all "media" errors.您可以使用onError道具来捕获所有“媒体”错误。 Setup errors can be caught using onSetupError prop.可以使用onSetupError捕获设置错误。 (PS In newer versions of library you should be able to use onError to catch both error types) Here is a working example how to handle error with code 102404 : (PS 在较新版本的库中,您应该能够使用onError来捕获两种错误类型)这是一个如何处理代码为102404错误的工作示例

import ReactJWPlayer from "react-jw-player";

export default function App() {
  
  const setupErrorHandler= (error) => {
    console.log("Setup error");
    console.log(error);
    if (error && error.code === 102404) {
      window.alert(error.message);
    }
    //here you write similar if condition to check if error has error 
      code 232404
    if(error && error.code === 232404){
        //do something..
    }
  };

 const mediaErrorHandler= (error) => {
    console.log("Media error");
    console.log(error);
    //handle error
  };

  return (
    <div className="App">
      <div
        className="jw-video-container"
        data-mediaid="TAITbudl"
        style={{ height: "100%", width: "100%" }}
      >
        <ReactJWPlayer
          playerId="TAITbudl"
          playerScript="https://content.jwplatform.com/libraries/j9BLvpMc.js"
          playlist="https://cdn.jwplayer.com/v2/playlists/vXggtmeu"
         
          onError={(event) => mediaErrorHandler(event)}
          onSetupError={(event) => setupErrorHandler(event)}
        />
      </div>
    </div>
  );
}

Note : All jwplayer errors have this form :注意:所有jwplayer错误都具有以下形式:

 {
      "code": 104153,
      "message": "Sorry, the video player failed to load.",
      "sourceError": { Error object | null },
      "type": "setupError"
    }

See documentation查看文档

以某种方式使用其他国家的 VPN 解决了​​这个问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM