Files
RTSPtoWEBPlayer/index.html
2024-02-13 15:09:18 +03:00

62 lines
2.1 KiB
HTML

<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>RTSPtoWEBPlayer demo</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
<script src="dist/RTSPtoWEBPlayer.js"></script>
</head>
<body>
<div class="container">
<h2 class="text-center mt-3">RTSPtoWEBPlayer Example</h2>
<div class="row">
<div class="col-12">
<div class="input-group mb-3">
<input type="text" class="form-control" placeholder="url link" id="link"
value=""/>
<button class="btn btn-outline-secondary" type="button" onclick="play()">PLAY</button>
</div>
<h6 class="text-center mb-3"><small><a href="#" id="outerLink"></a></small></h6>
</div>
<div class="col-12">
<div id="player"></div>
</div>
</div>
</div>
</body>
<script>
const options = {
parentElement: document.getElementById('player'),
debug: true,
onWsClose: (code,reason)=>{
console.log(code,reason);
},
};
const player = new RTSPtoWEBPlayer(options);
const play = () => {
const link = document.getElementById("link").value;
const url = new URL(window.location.href);
if (link !== '') {
player.load(link);
outerLink.innerHTML = `${url.origin + url.pathname + url.search}#${link}`;
outerLink.setAttribute('href', `${url.origin + url.pathname + url.search}#${link}`)
}
}
if (window.location.hash) {
try {
const href = new URL(window.location.hash.substr(1));
document.getElementById("link").value = window.location.hash.substr(1);
play();
} catch (e) {
console.log(e);
}
}
</script>
</html>