Help Center/ Live/ Low Latency Live Client SDK Reference/ Web SDK/ Best Practices/ Sample Code/ Automatic Downgrade
Updated on 2024-11-15 GMT+08:00
Automatic Downgrade
Sample code of automatic downgrade:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Downgrade Demo</title>
<script src="sdk/HWLLSPlayer.js"></script>
</head>
<body>
<div id="preview" style="width: 1280px; height: 720px; position:relative;"></div>
<button id="btnStartPlay">start play</button>
<button id="btnStopPlay">stop play</button>
<script>
HWLLSPlayer.setParameter('AUTO_DOWNGRADE', true)
const btnStartPlay = document.getElementById('btnStartPlay')
const btnStopPlay = document.getElementById('btnStopPlay')
const streamUrl = 'your stream url'
const client = HWLLSPlayer.createClient()
bindEvent(client)
btnStartPlay.addEventListener('click', () => {
startPlay(client, streamUrl, 'preview')
})
btnStopPlay.addEventListener('click', () => {
stopPlay(client)
})
function bindEvent(client) {
client.on('Error', (error) => {
console.log(`error: ${JSON.stringify(error)}`)
})
client.on('player-changed', (mediaFormat) => {
console.log(`player changed:${mediaFormat}`)
})
}
function startPlay(client, url, elementId) {
client.startPlay(url, {
elementId: elementId,
})
}
function stopPlay(client) {
client.stopPlay()
}
</script>
</body>
</html> Parent topic: Sample Code
What is your overall rating for this page?
0
1
2
3
4
5
6
7
8
9
10
Very dissatisfiedVery satisfied
Thank you very much for your feedback. We will continue working to improve the documentation.
The system is busy. Please try again later.