-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(showcase): showcases for custom text tracks handling
Introduces new showcases for integrators to benefit from the inclusion of custom text tracks in the pillarbox player (see SRGSSR/pillarbox-web#207). The showcases cover the implementation of: handling blocked segments, displaying current chapters, and managing time intervals. Code examples with ample comments have been added to provide developers with technical insight on how to integrate these features.
- Loading branch information
Showing
10 changed files
with
491 additions
and
25 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
<!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.0"/> | ||
<title>Pillarbox Demo - Detect blocked segment</title> | ||
<link rel="icon" type="image/x-icon" href="../../img/favicon.ico"> | ||
<link rel="stylesheet" href="./static-showcase.scss"/> | ||
<link rel="stylesheet" href="./blocked-segment.scss"/> | ||
</head> | ||
|
||
<body> | ||
<core-demo-header></core-demo-header> | ||
<div class="showcase-content"> | ||
<h2>Detect blocked segment</h2> | ||
<div class="video-container"> | ||
<video-js id="video-element-id" class="pillarbox-js" controls crossorigin="anonymous"></video-js> | ||
</div> | ||
|
||
<button class="showcase-btn" id="close-btn">Close this window</button> | ||
</div> | ||
|
||
<script type="module" data-implementation> | ||
// Import the pillarbox library | ||
import pillarbox from '@srgssr/pillarbox-web'; | ||
|
||
// Register a plugin to display notifications on blocked segments | ||
pillarbox.registerPlugin('blockedSegmentNotification', function(options) { | ||
// Get a reference to the player instance | ||
const player = this; | ||
|
||
// Wait for the player to be ready | ||
player.ready(() => { | ||
// Create a component for displaying the blocked segment notification | ||
const blockSegmentNotification = player.addChild('component', { | ||
className: 'pbw-blocked-segment-notification' | ||
}); | ||
|
||
// Hide the notification initially | ||
blockSegmentNotification.hide(); | ||
|
||
// Variable to store the timeout ID for clearing later | ||
let timeoutId = undefined; | ||
|
||
// Listen for the 'loadeddata' event on the player, this ensures that text tracks are available | ||
player.on('loadeddata', () => { | ||
// Get the text track with the ID 'srgssr-blocked-segments' | ||
const blockedSegments = player.textTracks().getTrackById('srgssr-blocked-segments'); | ||
|
||
// Add a listener for the 'cuechange' event on the blocked segments text track | ||
blockedSegments?.on('cuechange', () => { | ||
// Check if there are active cues in the blocked segments text track | ||
if (blockedSegments.activeCues.length > 0) { | ||
// If there is an existing timeout, clear it | ||
if (timeoutId) clearTimeout(timeoutId); | ||
|
||
// Parse the JSON content of the active cue to get the blocked segment information | ||
const blockSegment = JSON.parse(blockedSegments.activeCues[0].text); | ||
const blockReason = blockSegment.blockReason; | ||
|
||
// Update the displayed notification text with the appropriate message based on the block reason | ||
blockSegmentNotification.el().textContent = options.i18n[blockReason] ?? options.i18n['UNKNOWN']; | ||
|
||
// Show the blocked segment notification | ||
blockSegmentNotification.show(); | ||
|
||
// Set a timeout to hide the notification after a specified delay | ||
timeoutId = setTimeout(() => { | ||
blockSegmentNotification.hide(); | ||
timeoutId = undefined; | ||
}, options.delay); | ||
} | ||
}); | ||
}); | ||
}); | ||
}); | ||
|
||
// Create a pillarbox player instance with the blockedSegmentNotification plugin | ||
const player = pillarbox( | ||
'video-element-id', { | ||
fill: true, | ||
plugins: { | ||
blockedSegmentNotification: { | ||
delay: 5000, // Delay in milliseconds before hiding the notification | ||
i18n: { // Labels for different block reasons | ||
STARTDATE: 'ⓘ A portion of the video is not yet available', | ||
ENDDATE: 'ⓘ A section of the video has expired', | ||
LEGAL: 'ⓘ For legal reasons, a section of the video content is omitted', | ||
COMMERCIAL: 'ⓘ A commercial break has been excluded', | ||
GEOBLOCK: 'ⓘ This segment of the video is not accessible in your region', | ||
AGERATING18: 'ⓘ A segment suitable for 18 years and older is omitted', | ||
AGERATING12: 'ⓘ A segment suitable for 12 years and older is omitted', | ||
UNKNOWN: 'ⓘ Due to an unidentified issue, a segment of the video is omitted.' | ||
} | ||
} | ||
} | ||
} | ||
); | ||
|
||
// Load the video source for the player | ||
player.src({ src: 'urn:rts:video:10894383', type: 'srgssr/urn' }); | ||
</script> | ||
|
||
<script type="module"> | ||
import pillarbox from '@srgssr/pillarbox-web'; | ||
import '../../src/layout/header/core-demo-header-component.js'; | ||
|
||
document.querySelector('#close-btn').addEventListener('click', () => { | ||
window.close(); | ||
}); | ||
|
||
window.pillarbox = pillarbox; | ||
</script> | ||
|
||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
.pbw-blocked-segment-notification { | ||
position: absolute; | ||
right: var(--size-5); | ||
bottom: var(--size-9); | ||
display: flex; | ||
align-items: center; | ||
height: var(--size-6); | ||
color: white; | ||
background-color: rgb(0 0 0 / 70%); | ||
border-radius: var(--radius-3); | ||
box-shadow: var(--shadow-3); | ||
backdrop-filter: blur(5px); | ||
padding-inline: var(--size-2); | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
.pbw-current-chapter { | ||
position: absolute; | ||
top: calc(var(--size-8) * -1); | ||
left: var(--size-4); | ||
display: flex; | ||
width: var(--size-15); | ||
height: var(--size-9); | ||
color: white; | ||
background-color: rgb(0 0 0 / 50%); | ||
border-radius: var(--radius-2); | ||
box-shadow: var(--shadow-3); | ||
backdrop-filter: sepia(50%); | ||
} | ||
|
||
.vjs-layout-medium { | ||
.pbw-current-chapter { | ||
width: var(--size-14); | ||
} | ||
} | ||
|
||
.vjs-layout-tiny, | ||
.vjs-layout-x-small, | ||
.vjs-layout-small { | ||
.pbw-current-chapter { | ||
display: none; | ||
} | ||
} | ||
|
||
.pbw-chapter-title { | ||
display: -webkit-box; | ||
padding: var(--size-1) var(--size-2); | ||
overflow: hidden; | ||
font-weight: var(--font-weight-3); | ||
text-overflow: ellipsis; | ||
-webkit-line-clamp: 4; | ||
-webkit-box-orient: vertical; | ||
} | ||
|
||
.pbw-chapter-thumbnail { | ||
border-top-left-radius: var(--radius-2); | ||
border-bottom-left-radius: var(--radius-2); | ||
box-shadow: var(--inner-shadow-3); | ||
} |
Oops, something went wrong.