Hi Everyone
Trying to create a custom video player using the API, and I can get the player to show up, but no video, no logo overlay. I also want to add a custom thumbnail. yes, there is also a js file that will count viewers, not even ready to test that yet.
Can someone take a look and tell where I am foo-barred?
Thanks In Advance
<!DOCTYPE html>
<html>
<head>
<title>My Video Player with Counter EDITED</title>
</head>
<body>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Cloudflare Stream API Example ARCHIVED VIDEO</title>
<style>
/* CSS to position the logo in the top right corner of the video player */
.logo {
position: absolute;
top: 10px;
right: 10px;
}
</style>
<script src="ViewerCount.js"></script>
</head>
<body>
<video id="video-player" controls></video>
<script>
const STREAM_API_URL = 'https://api.cloudflare.com/client/v4/accounts/{accountid}/stream';
const ACCOUNT_ID = 'ACCOUNT ID HERE';
const VIDEO_ID = 'VIDEO ID HERE';
const STREAM_API_TOKEN = 'STREAM API TOKEN';
const fetchVideo = async () => {
const response = await fetch(`${STREAM_API_URL}/videos/${VIDEO_ID}`, {
headers: {
'Authorization': `Bearer ${STREAM_API_TOKEN}`
}
});
if (!response.ok) {
throw new Error(`Failed to fetch video: ${response.status}`);
}
const data = await response.json();
// get the video URL
const videoUrl = data.result.playback.hls;
// get the thumbnail URL
const thumbnailUrl = data.result.thumbnail_url;
// create an HTML video element
const videoElement = document.getElementById('video-player');
// set the video source
videoElement.src = videoUrl;
// set the thumbnail as the poster image
videoElement.poster = thumbnailUrl;
// create an HTML image element for the logo
const logoElement = document.createElement('img');
// set the logo image source
logoElement.src = 'http://golivesportscast.com/cfl/ICON3.png';
// add a class to the logo element for positioning
logoElement.className = 'logo';
// add the logo to the video player
videoElement.parentNode.insertBefore(logoElement, videoElement);
};
fetchVideo();
</script>
</body>
</html>