我有一个react代码,如下所示,它在页面加载时呈现播放器。只有条件为真时,代码才会进入if块。
const player = ()=> {
if(condition) {
return (
<ReactJWPlayer
playlist={[props.playlist]}
/>
)
}
}
问题声明:用于错误代码232011
,我看到以下错误消息:
This video file cannot be played
(Error Code: 232011)
我想知道我需要在上面的react代码中做什么更改,这样我就可以在播放器中用下面的错误消息来替换上面的错误消息。
Video will be available soon
发布于 2021-07-13 19:28:29
您必须使用intl.{lang}.errors
对象。此对象本地化播放机中显示的错误消息。
为了配置intl.{lang}.errors
,必须使用react公开的customProps
选项直接应用于JW实例。
您可以只使用en
,也可以根据用例添加额外的语言支持。
import { useRef } from "react";
import ReactJWPlayer from "react-jw-player";
import ReactDOM from "react-dom";
export default function App() {
const jwPlayerRef = useRef();
const myErrorHandler = (err) => {
console.log(err);
// Find the Node where error message is shown
const errorNode = ReactDOM.findDOMNode(
jwPlayerRef.current
).getElementsByClassName("jw-error-text");
// If the error node exists, replace both message and code
if (errorNode && errorNode.length)
errorNode[0].innerText = "Custom Error Message";
};
return (
<div className="App">
<div
className="jw-video-container"
data-mediaid="TAITbudl"
style={{ height: "100%", width: "100%" }}
>
<ReactJWPlayer
ref={jwPlayerRef}
playerId="TAITbudl"
playerScript="https://content.jwplatform.com/libraries/j9BLvpMc.js"
playlist="https://cdn.jwplayer.com/v2/media/123"
onError={myErrorHandler}
onSetupError={myErrorHandler}
customProps={{ // <= Official way to override the error message
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.",
cantPlayInBrowser:
"The video cannot be played in this browser.",
cantPlayVideo: "This is my custom error Message",
errorCode: "Code - ",
liveStreamDown:
"The live stream is either down or has ended.",
protectedContent:
"There was a problem providing access to protected content.",
technicalError:
"This video cannot be played because of a technical error."
}
}
}
}}
/>
</div>
</div>
);
}
intl
对象允许您添加新的语言翻译,.- 文档
请注意,getElementsByClassName("jw-error-text")
是一个黑客,如果JW决定更改这个类名,或者混淆它,这个黑客就会崩溃。
https://stackoverflow.com/questions/68322358
复制相似问题