gpt4 book ai didi

javascript - 在实时播放器中显示自定义错误消息

转载 作者:行者123 更新时间:2023-12-04 12:28:53 24 4
gpt4 key购买 nike

我有一个 react 代码 如下所示,它在页面加载时呈现播放器。仅当条件为真时,代码才会进入 if block 。

const player = ()=> {
if(condition) {
return (
<ReactJWPlayer
playlist={[props.playlist]}
/>
)
}
}
问题陈述:对于错误代码 232011 ,我看到以下错误消息:
[![在此处输入图像描述][1]][1]
This video file cannot be played
(Error Code: 232011)
我想知道我需要在上面的 react 代码中进行哪些更改,以便我可以将上面的错误消息替换为播放器中的以下错误消息。
Video will be available soon

最佳答案

您必须使用 intl.{lang}.errors 目的。此对象本地化播放器中显示的错误消息。
为了配置 intl.{lang}.errors ,您将不得不使用 customProps react-jw-player 公开的选项直接应用于 JW Player 实例。
你可以坚持 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>
);
}

Edit React-JW-Player Custom Error Message

The intl object allows you to add new language translations, [...] - Docs


请注意 getElementsByClassName("jw-error-text")是一个 hack,如果 JW Player 决定更改类名或混淆它,这个 hack 将会中断。

关于javascript - 在实时播放器中显示自定义错误消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68322358/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com