更新时间:2024-11-15 GMT+08:00
自动播放失败监听
自动播放失败监听的代码示例,如下所示:
<!DOCTYPE html> <html> <head> <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no" /> <title>音频受限demo</title> <style> html, body { width: 100%; height: 100%; padding: 0; margin: 0; } .preview_player { width: 1280px; height: 720px; margin: 20px auto; border: 1px solid #ddd; position: relative; } .preview_player_el { width: 100%; height: 100%; } .unmute_mask { position: absolute; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0, 0, 0, 0.5); text-align: center; display: none; } .unmute_btn { display: inline-block; padding: 10px; color: rgb(50, 250, 50); border: 1px solid rgb(50, 250, 50); background: rgba(50, 250, 50, 0.3); transform: translateY(400px); cursor: pointer; } </style> <script type="text/javascript" src="./sdk/HWLLSPlayer.js"></script> </head> <body> <div class="preview_player"> <div id="preview" class="preview_player_el"></div> <div class="unmute_mask" id="unmute-mask"> <div class="unmute_btn" onclick="replayAction()">点击取消静音</div> </div> </div> <script type="text/javascript"> const playClient = HWLLSPlayer.createClient() const unmuteMask = document.getElementById('unmute-mask') const replayAction = function () { playClient.replay() unmuteMask.style.display = 'none' } // 注册音频受限处理事件 const initEvent = function () { playClient.on('Error', (resp) => { //音频受限报错 if (resp.errCode === 51000000) { //界面添加取消静音按钮 unmuteMask.style.display = 'block' } }) } initEvent() // 播放视频 const streamUrl = 'your stream url' const options = { elementId: 'preview', autoPlay: true, } playClient.startPlay(streamUrl, options) </script> </body> </html>
父主题: 代码示例