Skip to content

Commit 7b11d87

Browse files
committed
Multimedia Player: added default cc functionality
1 parent 9529e94 commit 7b11d87

File tree

8 files changed

+203
-7
lines changed

8 files changed

+203
-7
lines changed

site/pages/docs/ref/multimedia/multimedia-en.hbs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,21 @@
230230
</dl>
231231
</td>
232232
</tr>
233+
<tr>
234+
<td><code>closedCaptions</code></td>
235+
<td>
236+
<p>Displays the closed captions by default when the video is played for the first time.</p>
237+
</td>
238+
<td>Add <pre><code>data-wb-mltmd='{"closedCaptions": true}'</code></pre> to the element with <code>class="wb-mltmd"</code>.</td>
239+
<td>
240+
<dl>
241+
<dt><code>false (default)</code></dt>
242+
<dd>The video does not display closed captions on first playback</dd>
243+
<dt><code>true</code></dt>
244+
<dd>The video displays closed captions on first playback</dd>
245+
</dl>
246+
</td>
247+
</tr>
233248
</tbody>
234249
</table>
235250
</section>

site/pages/docs/ref/multimedia/multimedia-fr.hbs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,21 @@
231231
</dl>
232232
</td>
233233
</tr>
234+
<tr>
235+
<td><code>closedCaptions</code></td>
236+
<td>
237+
<p>Affiche les sous-titres par défaut lorsque la vidéo est lue pour la première fois.</p>
238+
</td>
239+
<td>Ajoutez <pre><code>data-wb-mltmd='{"closedCaptions": true}'</code></pre> à l'élément avec l'attribut <code>class="wb-mltmd"</code>.</td>
240+
<td>
241+
<dl>
242+
<dt><code>false (par défaut)</code></dt>
243+
<dd>La vidéo n'affiche pas de sous-titres lors de la première lecture</dd>
244+
<dt><code>true</code></dt>
245+
<dd>La vidéo affiche des sous-titres lors de la première lecture</dd>
246+
</dl>
247+
</td>
248+
</tr>
234249
</tbody>
235250
</table>
236251
</section>

src/plugins/multimedia/_base.scss

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,12 @@
117117
}
118118

119119
&.cc_on {
120-
.wb-mm-cc {
121-
display: table;
122-
height: calc(#{$line-height-base * $mm-cc-lines}em + #{$mm-cc-padding * 2});
123-
padding: $mm-cc-padding;
120+
&.played {
121+
.wb-mm-cc {
122+
display: table;
123+
height: calc(#{$line-height-base * $mm-cc-lines}em + #{$mm-cc-padding * 2});
124+
padding: $mm-cc-padding;
125+
}
124126
}
125127

126128
&:not(.errmsg) {

src/plugins/multimedia/multimedia-en.hbs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,40 @@
306306
</details>
307307
</section>
308308
</div>
309+
310+
311+
<div class="row">
312+
<section class="col-md-6">
313+
<h3>MPEG4 (H264 + AAC) and WebM (VP8) source with closed captions by default</h3>
314+
<figure class="wb-mltmd" data-wb-mltmd='{"closedCaptions": true}'>
315+
<video poster="demo/img/video1-en.jpg" title="Looking for a Job">
316+
<source type="video/webm" src="https://wet-boew.github.io/wet-boew-attachments/videos/video1-en.webm" />
317+
<source type="video/mp4" src="https://wet-boew.github.io/wet-boew-attachments/videos/video1-en.mp4" />
318+
<track src="cpts-lg-en.html" kind="captions" data-type="text/html" srclang="en" label="English" />
319+
</video>
320+
<figcaption>
321+
<p>Looking for a Job (<a href="cpts-lg-en.html">Transcript</a>)</p>
322+
</figcaption>
323+
</figure>
324+
325+
<details class="mrgn-tp-md mrgn-bttm-lg">
326+
<summary>View code</summary>
327+
<section>
328+
<h4>In-page HTML</h4>
329+
<pre><code>&lt;figure class="wb-mltmd" data-wb-mltmd='{"closedCaptions": true}'&gt;
330+
&lt;video poster="demo/img/video1-en.jpg" title="Looking for a Job"&gt;
331+
&lt;source type="video/webm" src="https://wet-boew.github.io/wet-boew-attachments/videos/video1-en.webm" /&gt;
332+
&lt;source type="video/mp4" src="https://wet-boew.github.io/wet-boew-attachments/videos/video1-en.mp4" /&gt;
333+
&lt;track src="cpts-lg-en.html" kind="captions" data-type="text/html" srclang="en" label="English" /&gt;
334+
&lt;/video&gt;
335+
&lt;figcaption&gt;
336+
&lt;p&gt;Looking for a Job (&lt;a href="cpts-lg-en.html"&gt;Transcript&lt;/a&gt;)&lt;/p&gt;
337+
&lt;/figcaption&gt;
338+
&lt;/figure&gt;</code></pre>
339+
</section>
340+
</details>
341+
</section>
342+
</div>
309343
</section>
310344

311345
<section id="mltmd-overlay" class="wb-overlay modal-content overlay-def wb-popup-full">

src/plugins/multimedia/multimedia-fr.hbs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,39 @@
316316
</details>
317317
</section>
318318
</div>
319+
320+
<div class="row">
321+
<section class="col-md-6">
322+
<h3>MPEG4 (H264 + AAC) et WebM (VP8) avec sous-titre par défaut</h3>
323+
<figure class="wb-mltmd" data-wb-mltmd='{"closedCaptions": true}'>
324+
<video poster="demo/img/video1-fr.jpg" title="Trouver un emploi">
325+
<source type="video/webm" src="https://wet-boew.github.io/wet-boew-attachments/videos/video1-fr.webm" />
326+
<source type="video/mp4" src="https://wet-boew.github.io/wet-boew-attachments/videos/video1-fr.mp4" />
327+
<track src="cpts-lg-fr.html" kind="captions" data-type="text/html" srclang="fr" label="Français" />
328+
</video>
329+
<figcaption>
330+
<p>Trouver un emploi (<a href="cpts-lg-fr.html">Transcription</a>)</p>
331+
</figcaption>
332+
</figure>
333+
334+
<details class="mrgn-tp-md mrgn-bttm-lg">
335+
<summary>Visualiser le code</summary>
336+
<section>
337+
<h4>HTML dans la page</h4>
338+
<pre><code>&lt;figure class=&quot;wb-mltmd&quot; data-wb-mltmd='{"closedCaptions": true}'&gt;
339+
&lt;video poster=&quot;demo/img/video1-fr.jpg&quot; title=&quot;Trouver un emploi&quot;&gt;
340+
&lt;source type=&quot;video/webm&quot; src=&quot;https://wet-boew.github.io/wet-boew-attachments/videos/video1-fr.webm&quot; /&gt;
341+
&lt;source type=&quot;video/mp4&quot; src=&quot;https://wet-boew.github.io/wet-boew-attachments/videos/video1-fr.mp4&quot; /&gt;
342+
&lt;track src=&quot;cpts-lg-fr.html&quot; kind=&quot;captions&quot; data-type=&quot;text/html&quot; srclang=&quot;fr&quot; label=&quot;Français&quot; /&gt;
343+
&lt;/video&gt;
344+
&lt;figcaption&gt;
345+
&lt;p&gt;Trouver un emploi (&lt;a href=&quot;cpts-lg-fr.html&quot;&gt;Transcription&lt;/a&gt;)&lt;/p&gt;
346+
&lt;/figcaption&gt;
347+
&lt;/figure&gt;</code></pre>
348+
</section>
349+
</details>
350+
</section>
351+
</div>
319352
</section>
320353

321354
<section id="mltmd-overlay" class="wb-overlay modal-content overlay-def wb-popup-full">

src/plugins/multimedia/multimedia-youtube-en.hbs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,32 @@
134134
</section>
135135
</div>
136136

137+
<div class="row">
138+
<section class="col-md-6">
139+
<h2>Example with closed captions by default</h2>
140+
<figure class="wb-mltmd" data-wb-mltmd='{"closedCaptions": true}'>
141+
<video title="Suspect">
142+
<source type="video/youtube" src="https://www.youtube.com/watch?v=9znKJqnFuuY">
143+
</video>
144+
<figcaption>
145+
<p>Suspect (<a href="https://www.canada.ca/en/health-canada/services/video/suspect.html#trans">Transcript</a>)</p>
146+
</figcaption>
147+
</figure>
148+
149+
<details class="mrgn-tp-md">
150+
<summary>View code</summary>
151+
<pre><code>&lt;figure class=&quot;wb-mltmd&quot; data-wb-mltmd='{"closedCaptions": true}'&gt;
152+
&lt;video title=&quot;Suspect&quot;&gt;
153+
&lt;source type=&quot;video/youtube&quot; src=&quot;https://www.youtube.com/watch?v=9znKJqnFuuY&quot; /&gt;
154+
&lt;/video&gt;
155+
&lt;figcaption&gt;
156+
&lt;p&gt;Suspect&lt;/p&gt;
157+
&lt;/figcaption&gt;
158+
&lt;/figure&gt;</code></pre>
159+
</details>
160+
</section>
161+
</div>
162+
137163
<div class="row">
138164
<section class="col-md-6">
139165
<h2>Video with defined video frame size</h2>

src/plugins/multimedia/multimedia-youtube-fr.hbs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,32 @@
133133
</section>
134134
</div>
135135

136+
<div class="row">
137+
<section class="col-md-6">
138+
<h2>Exemple avec sous-titre par défaut</h2>
139+
<figure class="wb-mltmd" data-wb-mltmd='{"closedCaptions": true}'>
140+
<video title="Suspect">
141+
<source type="video/youtube" src="https://www.youtube.com/watch?v=LLg-UsTr7us">
142+
</video>
143+
<figcaption>
144+
<p>Suspect (<a href="https://www.canada.ca/fr/sante-canada/services/video/suspect.html#trans">Transcription</a>)</p>
145+
</figcaption>
146+
</figure>
147+
148+
<details class="mrgn-tp-md">
149+
<summary>View code</summary>
150+
<pre><code>&lt;figure class=&quot;wb-mltmd&quot; data-wb-mltmd='{"closedCaptions": true}'&gt;
151+
&lt;video title=&quot;Suspect&quot;&gt;
152+
&lt;source type=&quot;video/youtube&quot; src=&quot;https://www.youtube.com/watch?v=LLg-UsTr7us&quot; /&gt;
153+
&lt;/video&gt;
154+
&lt;figcaption&gt;
155+
&lt;p&gt;Suspect&lt;/p&gt;
156+
&lt;/figcaption&gt;
157+
&lt;/figure&gt;</code></pre>
158+
</details>
159+
</section>
160+
</div>
161+
136162
<div class="row">
137163
<section class="col-md-6">
138164
<h2>Vidéo avec dimensions définies du cadre de la vidéo</h2>

src/plugins/multimedia/multimedia.js

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ var componentName = "wb-mltmd",
2727
templateLoadedEvent = "templateloaded" + selector,
2828
cuepointEvent = "cuepoint" + selector,
2929
captionClass = "cc_on",
30+
firstPlayClass = "played",
31+
defaultCaptions = false,
3032
multimediaEvents = [
3133
"durationchange",
3234
"playing",
@@ -581,7 +583,8 @@ var componentName = "wb-mltmd",
581583
},
582584
$mltmPlayerElm,
583585
mltmPlayerElm,
584-
isMuted;
586+
isMuted,
587+
settings;
585588

586589
switch ( event.data ) {
587590
case null: // init
@@ -612,6 +615,13 @@ var componentName = "wb-mltmd",
612615
$mltmPlayerElm = $media.parentsUntil( selector ).parent();
613616
mltmPlayerElm = $mltmPlayerElm.get( 0 );
614617

618+
//Check if closed captions should be enabled on play
619+
settings = wb.getData( mltmPlayerElm, componentName );
620+
621+
if ( settings.closedCaptions !== null && settings.closedCaptions === true ) {
622+
youTubeApi.call( mltmPlayerElm, "setCaptionsVisible", true );
623+
}
624+
615625
// Need to be muted here
616626
isMuted = mltmPlayerElm.player( "getMuted" );
617627

@@ -706,6 +716,10 @@ $document.on( initializedEvent, selector, function( event ) {
706716
if ( settings !== undef ) {
707717
data.shareUrl = settings.shareUrl;
708718
data.fullscreen = settings.fullscreenBtn || false;
719+
data.closedCaptions = settings.closedCaptions || false;
720+
if ( data.closedCaptions !== undef ) {
721+
defaultCaptions = data.closedCaptions;
722+
}
709723
}
710724

711725
$this.addClass( type );
@@ -868,7 +882,8 @@ $document.on( renderUIEvent, selector, function( event, type, data ) {
868882
captionsUrl = wb.getUrlParts( data.captions ),
869883
currentUrl = wb.getUrlParts( window.location.href ),
870884
$media = data.media,
871-
$eventReceiver;
885+
$eventReceiver,
886+
$button;
872887

873888
$media
874889
.after( tmpl( template, data ) )
@@ -926,6 +941,29 @@ $document.on( renderUIEvent, selector, function( event, type, data ) {
926941
if ( data.fullscreen ) {
927942
$this.attr( "data-fullscreen-btn", true );
928943
}
944+
945+
// Show captions by default if configured to do so
946+
let captionStatus;
947+
948+
if ( $this.data( "wbMltmd" ) !== undef ) {
949+
captionStatus = $this.data( "wbMltmd" ).closedCaptions;
950+
}
951+
952+
if ( captionStatus !== undef && defaultCaptions !== undef && defaultCaptions === true ) {
953+
954+
$this.addClass( captionClass );
955+
956+
// Trigger caption visibility change event only on the first time the video plays
957+
defaultCaptions = true;
958+
959+
$button = $this.find( ".cc" );
960+
961+
$button
962+
.attr( {
963+
"aria-pressed": true
964+
} );
965+
966+
}
929967
}
930968
} );
931969

@@ -1053,7 +1091,8 @@ $document.on( multimediaEvents, selector, function( event, simulated ) {
10531091
$this = $( eventTarget ),
10541092
invStart = "<span class='wb-inv'>",
10551093
invEnd = "</span>",
1056-
currentTime, $button, $slider, buttonData, isPlay, isMuted, isCCVisible, skipTo, volume;
1094+
currentTime, $button, $slider, buttonData, isPlay, isMuted, isCCVisible, skipTo, volume,
1095+
firstPlay = false;
10571096
switch ( eventType ) {
10581097
case "playing":
10591098
case "pause":
@@ -1064,6 +1103,12 @@ $document.on( multimediaEvents, selector, function( event, simulated ) {
10641103
if ( isPlay ) {
10651104
$this.addClass( "playing" );
10661105
$this.find( ".progress" ).addClass( "active" );
1106+
1107+
if ( firstPlay === false ) {
1108+
$this.addClass( firstPlayClass );
1109+
firstPlay = true;
1110+
}
1111+
10671112
} else {
10681113
if ( eventType === "ended" ) {
10691114
this.loading = clearTimeout( this.loading );

0 commit comments

Comments
 (0)