Skip to content

Commit

Permalink
feat(FEC-14087): define audio-description audio tracks (#797)
Browse files Browse the repository at this point in the history
### Description of the Changes

resolves: https://kaltura.atlassian.net/browse/FEC-14087

### CheckLists

- [ ] changes have been done against master branch, and PR does not
conflict
- [ ] new unit / functional tests have been added (whenever applicable)
- [ ] test are passing in local environment
- [ ] Travis tests are passing (or test results are not worse than on
master branch :))
- [ ] Docs have been updated
  • Loading branch information
semarche-kaltura authored Nov 7, 2024
1 parent 912c31b commit 3c2e365
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 4 deletions.
13 changes: 13 additions & 0 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ var config = {
autoplay: false,
loop: false,
allowMutedAutoPlay: true,
updateAudioDescriptionLabels: true,
muted: false,
pictureInPicture: true,
options: {
Expand Down Expand Up @@ -792,6 +793,7 @@ var config = {
> loop: boolean,
> autopause: boolean,
> allowMutedAutoPlay: boolean,
> updateAudioDescriptionLabels: boolean,
> muted: boolean,
> pictureInPicture: boolean,
> options: PKPlaybackOptionsObject,
Expand All @@ -818,6 +820,7 @@ var config = {
> autoplay: false,
> loop: false,
> allowMutedAutoPlay: true,
> updateAudioDescriptionLabels: true,
> muted: false,
> pictureInPicture: true,
> playAdsWithMSE: false,
Expand Down Expand Up @@ -1078,6 +1081,16 @@ var config = {
>
> ##
>
> > ### config.playback.updateAudioDescriptionLabels
> >
> > ##### Type: `boolean`
> >
> > ##### Default: `true`
> >
> > ##### Description: Updates audio flavors that has "audio_description" tag
>
> ##
>
> > ### config.playback.autopause
> >
> > ##### Type: `boolean`
Expand Down
1 change: 1 addition & 0 deletions flow-typed/types/playback-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ declare type PKPlaybackConfigObject = {
preload: string,
autoplay: PKAutoPlayTypes,
allowMutedAutoPlay: boolean,
updateAudioDescriptionLabels: boolean,
muted: boolean,
pictureInPicture: boolean,
streamPriority: Array<PKStreamPriorityObject>,
Expand Down
1 change: 1 addition & 0 deletions src/player-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const DefaultConfig = {
loop: false,
autopause: false,
allowMutedAutoPlay: true,
updateAudioDescriptionLabels: true,
muted: false,
pictureInPicture: true,
options: {
Expand Down
11 changes: 8 additions & 3 deletions src/player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import getLogger, { getLogLevel, LogLevel, LogLevelType, setLogHandler, setLogLe
import StateManager from './state/state-manager';
import Track from './track/track';
import VideoTrack from './track/video-track';
import AudioTrack from './track/audio-track';
import AudioTrack, { audioDescriptionTrackHandler } from './track/audio-track';
import { PKTextTrack } from './track/text-track';
import TextStyle from './track/text-style';
import { processCues } from './track/text-track-display';
Expand Down Expand Up @@ -1294,7 +1294,7 @@ export default class Player extends FakeEventTarget {
* @returns {void}
* @public
*/
public changeQuality(track: any | string): void{
public changeQuality(track: any | string): void {
if (track === 'auto') {
this.enableAdaptiveBitrate();
} else {
Expand Down Expand Up @@ -2042,7 +2042,7 @@ export default class Player extends FakeEventTarget {
if (window.self !== window.top) {
const head = Utils.Dom.getElementBySelector('head');
let title = head.querySelector('title');
if (!title){
if (!title) {
title = Utils.Dom.createElement('title');
head.appendChild(title);
}
Expand Down Expand Up @@ -2470,6 +2470,11 @@ export default class Player extends FakeEventTarget {
*/
public _updateTracks(tracks: Array<Track>): void {
Player._logger.debug('Tracks changed', tracks);

if (this.config.playback.updateAudioDescriptionLabels) {
audioDescriptionTrackHandler(tracks, this._sources.metadata?.audioFlavors);
}

this._tracks = tracks?.concat(this._externalCaptionsHandler.getExternalTracks(tracks));
this._applyABRRestriction(this._config);
this._addTextTrackOffOption();
Expand Down
27 changes: 26 additions & 1 deletion src/track/audio-track.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,35 @@
//@flow
import Track from './track';

enum FlavorAssetTags {
AUDIO_ONLY = 'audio_only',
AUDIO_DESCRIPTION = 'audio_description'
}

/**
* Audio track representation of the player.
* @classdesc
*/
class AudioTrack extends Track {}

export function audioDescriptionTrackHandler(tracks: AudioTrack[], audioFlavors?: Array<any>): void {
if (tracks?.length && audioFlavors?.length) {
let audioTracksIndex = 0;
// iterate over the audio tracks and set the isAudioDescription flag based on the audioFlavors tags
tracks.forEach((track) => {
if (track instanceof AudioTrack) {
const isAudioDescription = audioFlavors[audioTracksIndex]?.tags?.includes(FlavorAssetTags.AUDIO_DESCRIPTION);
if (isAudioDescription) {
// set the language to ad-<language> for audio description tracks
track.language = `ad-${track.language}`;
if (!audioFlavors?.[audioTracksIndex]?.label) {
// add "Audio Description" to the label if custom label is not provided
track.label = `${track.label} - Audio Description`;
}
}
audioTracksIndex++;
}
});
}
}

export default AudioTrack;
9 changes: 9 additions & 0 deletions src/track/track.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,15 @@ export default class Track {
this._available = isAvailable;
}

/**
* Setter for the language of the track.
* @public
* @param {string} value - The language of the track.
*/
public set language(value: string) {
this._language = value;
}

/**
* @constructor
* @param {Object} settings - The track settings object.
Expand Down
1 change: 1 addition & 0 deletions src/types/metadata-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ export type PKMetadataConfigObject = {
tags?: Object,
epgId?: string,
recordingId?: string
audioFlavors?: Array<any>,
};
1 change: 1 addition & 0 deletions src/types/playback-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export type PKPlaybackConfigObject = {
preload: string,
autoplay: PKAutoPlayTypes,
allowMutedAutoPlay: boolean,
updateAudioDescriptionLabels: boolean,
muted: boolean,
pictureInPicture: boolean,
streamPriority: Array<PKStreamPriorityObject>,
Expand Down

0 comments on commit 3c2e365

Please sign in to comment.