首页 > 解决方案 > 如何在 JWPlayer 的错误消息中隐藏错误代码?

问题描述

我有一个如下所示的 React 代码,它呈现播放器。在下面的代码中,我将 ReactJWPlayer 组件与他们的 props 一起使用。为了配置intl.{lang}.errors,我使用了react-jw-player公开的 customProps 选项

const ReactJWPlayerContainer = props => {
    const [error, setError] = useState("");
    const [errorNode, setErrorNode] = useState(null);
 
    const player = ()=> {
            return (
                <ReactJWPlayer
                    playlist={[props.playlist]}
                    customProps={{
                        intl: {
                          en: {
                            errors: {
                              badConnection: "This video cannot be played because of a problem with your internet connection.",
                              cantLoadPlayer: "Sorry, the video player failed to load.",
                            },
                          },
                          fr: {
                            errors: {
                              badConnection: "This video cannot be played because of a problem with your internet connection.",
                              cantLoadPlayer: "Sorry, the video player failed to load.",
                            },
                          },
                        },
                      }}  
                />
            )
        }
    }

    return (
        <>
            {props.playlist && player()}
        </>
    )

}

如果播放器加载失败,上面的代码会成功显示带有相应错误代码的自定义错误消息。

问题陈述:

我想知道我需要在上面的 React 代码中进行哪些更改才能成功隐藏错误代码。在下面的屏幕截图中,我想隐藏该行 (Error Code: 232011)

标签: javascriptreactjsjwplayer

解决方案


您必须将 props.playlist 作为变量传递,但要作为数组项传递。

将此代码 playlist={[props.playlist]} 更改为 playlist={props.playlist}

我假设 props.playlist 是一个像这个例子一样的数组:

https://github.com/micnews/react-jw-player#playing-a-custom-playlist


推荐阅读