Skip to content

Commit

Permalink
fix(FEC-8594): when casting via Play on TV button the Captions/Audio …
Browse files Browse the repository at this point in the history
…is not displayed (#159)

If the player has started to play it will return the current played language.
Otherwise, it will return the configured language.
  • Loading branch information
Dan Ziv committed Nov 4, 2018
1 parent 10022ed commit 6ae6253
Showing 1 changed file with 24 additions and 4 deletions.
28 changes: 24 additions & 4 deletions src/common/cast/player-snapshot.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// @flow
import {KalturaPlayer} from '../../kaltura-player';
import {TextStyle} from 'playkit-js';
import {TextStyle, TrackType} from 'playkit-js';

/**
* @class PlayerSnapshot
Expand Down Expand Up @@ -52,13 +52,12 @@ class PlayerSnapshot {
advertising: ?Object;

constructor(player: KalturaPlayer) {
const activeTracks = player.getActiveTracks();
this.startTime = getStartTime(player);
this.autoplay = player.currentTime === 0 ? true : !player.paused;
this.textStyle = player.textStyle;
this.mediaInfo = player.getMediaInfo();
this.audioLanguage = activeTracks.audio && activeTracks.audio.language;
this.textLanguage = activeTracks.text && activeTracks.text.language;
this.audioLanguage = getLanguage(TrackType.AUDIO, player);
this.textLanguage = getLanguage(TrackType.TEXT, player);
this.advertising = player.config.plugins && player.config.plugins.ima;
}
}
Expand All @@ -84,4 +83,25 @@ function getStartTime(player: KalturaPlayer): number {
return player.currentTime;
}

/**
* Gets the audio/text language.
* If the player has started to play it will return the current played audio/text.
* Otherwise, it will return the configured audio/text.
* @private
* @param {string} type - The language type.
* @param {KalturaPlayer} player - The player.
* @returns {?string} - The audio language or undefined.
*/
function getLanguage(type: string, player: KalturaPlayer): ?string {
const activeTracks = player.getActiveTracks();
if (activeTracks[type]) {
return activeTracks[type].language;
}
try {
return player.config.playback[`${type}Language`];
} catch (e) {
return null;
}
}

export {PlayerSnapshot};

0 comments on commit 6ae6253

Please sign in to comment.