<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta http-equiv="Content-Type" content="application/vnd.hbbtv.xhtml+xml; charset=utf-8" />
<title>HBBTV m3u8 Streaming</title>
<link rel="stylesheet" type="text/css" href="style.css" />
<script type="text/javascript" src="script.js"></script>
</head>
<body onload="initApp();">
<object id="video" type="video/mp4" class="video-object"></object>
<div id="message" class="message">Press OK to start streaming</div>
</body>
</html>
html, body {
width: 1280px;
height: 720px;
margin: 0;
padding: 0;
font-family: Arial, sans-serif;
background-color: #000;
}
.video-object {
width: 1280px;
height: 720px;
position: absolute;
z-index: 1;
}
.message {
width: 100%;
position: absolute;
bottom: 10px;
z-index: 2;
background-color: rgba(0, 0, 0, 0.5);
color: #fff;
font-size: 24px;
text-align: center;
padding: 10px;
}
const STREAM_URL = 'https://your-m3u8-stream-url.m3u8';
function initApp() {
document.addEventListener('keydown', handleKeydown);
}
function handleKeydown(event) {
if (event.keyCode === 13) {
// Enter / OK key
playStream();
}
}
function playStream() {
const video = document.getElementById('video');
if (video.data && video.data.type === 'video/mpeg') {
video.type = 'application/vnd.apple.mpegurl'; // HbbTV 2.0 version
} else {
video.type = 'video/mpeg'; // HbbTV 1.5 version
}
video.data = STREAM_URL;
video.play(1);
const message = document.getElementById('message');
message.style.display = 'none';
}
Keep in mind that to test the application, you will need an HBBTV-enabled device or emulator, as HBBTV applications generally do not work in standard web browsers.+
The following example demonstrates an HBBTV website containing two buttons that will allow you to switch between two m3u8 streams.
- Create an HTML file (index.html):
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta http-equiv="Content-Type" content="application/vnd.hbbtv.xhtml+xml; charset=utf-8" />
<title>HBBTV Multiple m3u8 Streams</title>
<link rel="stylesheet" type="text/css" href="style.css" />
<script type="text/javascript" src="script.js"></script>
</head>
<body onload="initApp();">
<div id="container">
<object id="video" type="video/mp4" class="video-object"></object>
<button id="stream1" class="stream-btn">Stream 1</button>
<button id="stream2" class="stream-btn">Stream 2</button>
</div>
</body>
</html>
- Create a CSS file (style.css):
html, body {
width: 1280px;
height: 720px;
margin: 0;
padding: 0;
font-family: Arial, sans-serif;
background-color: #000;
}
#container {
position: relative;
}
.video-object {
width: 1280px;
height: 720px;
}
.stream-btn {
position: absolute;
bottom: 20px;
background-color: rgba(0, 0, 0, 0.5);
color: #fff;
border: none;
font-size: 24px;
padding: 10px 20px;
margin-right: 10px;
cursor: pointer;
z-index: 2;
}
#stream2 {
left: 200px;
}
- Create a JavaScript file (script.js):
const STREAM_URL_1 = 'https://your-m3u8-stream-url-1.m3u8';
const STREAM_URL_2 = 'https://your-m3u8-stream-url-2.m3u8';
function initApp() {
const stream1Btn = document.getElementById('stream1');
const stream2Btn = document.getElementById('stream2');
// Start with Stream 1
playStream(STREAM_URL_1);
stream1Btn.addEventListener('click', () => {
playStream(STREAM_URL_1);
});
stream2Btn.addEventListener('click', () => {
playStream(STREAM_URL_2);
});
}
function playStream(url) {
const video = document.getElementById('video');
video.type = 'application/vnd.apple.mpegurl'; // HbbTV 2.0 version
video.data = url;
video.play(1);
}
Replace the 'https://your-m3u8-stream-url-1.m3u8' and 'https://your-m3u8-stream-url-2.m3u8' with the URLs of the m3u8 streams you want to use in the script.js file.
This code sample creates an HBBTV website with a video object and two buttons labeled "Stream 1" and "Stream 2." When clicking on these buttons, the corresponding m3u8 stream will start playing.
As with the previous example, to test the application, you will need an HBBTV-enabled device or emulator, as HBBTV applications generally do not work in standard web browsers.