Skip to content

Commit

Permalink
feat: choose default text tracks on iOS by default (#36)
Browse files Browse the repository at this point in the history
  • Loading branch information
OrenMe authored and Dan Ziv committed Oct 2, 2017
1 parent e63c48e commit 3329366
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
createKalturaPlayerContainer,
validateTargetId,
validateProvidersConfig,
checkNativeHlsSupport,
setDefaultPlayerConfig,
setStorageConfig,
applyStorageSupport
} from "./utils/setup-helpers"
Expand All @@ -24,7 +24,7 @@ function setup(targetId: string, options: Object): KalturaPlayer {
let userPlayerConfig = extractPlayerConfig(options);
let userProvidersConfig = extractProvidersConfig(options);
let containerId = createKalturaPlayerContainer(targetId);
checkNativeHlsSupport(userPlayerConfig);
setDefaultPlayerConfig(userPlayerConfig);
evaluatePluginsConfig(userPlayerConfig);
setStorageConfig(options.disableUserCache, userPlayerConfig);
let player = loadPlayer(userPlayerConfig);
Expand Down
4 changes: 2 additions & 2 deletions src/storage/storage-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ export default class StorageManager {
StorageWrapper.setItem('volume', StorageManager._player.volume);
});
StorageManager._player.addEventListener(player.Event.AUDIO_TRACK_CHANGED, (event) => {
let audioTrack = event.payload.selectedAudioTrack;
const audioTrack = event.payload.selectedAudioTrack;
StorageWrapper.setItem('audioLanguage', audioTrack.language);
});
StorageManager._player.addEventListener(player.Event.TEXT_TRACK_CHANGED, (event) => {
let textTrack = event.payload.selectedTextTrack;
const textTrack = event.payload.selectedTextTrack;
StorageWrapper.setItem('textLanguage', textTrack.language);
});
}
Expand Down
29 changes: 29 additions & 0 deletions src/utils/setup-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,15 @@ function addKalturaPoster(metadata: Object, width: number, height: number): void
metadata.poster = `${metadata.poster}/height/${height}/width/${width}`;
}

/**
* preform different checks for setting default player settings
* @param {Object} playerConfig - the player config
* @returns {void}
*/
function setDefaultPlayerConfig(playerConfig: Object): void{
checkNativeHlsSupport(playerConfig);
checkNativeTextTracksSupport(playerConfig);
}
/**
* Sets config option for native HLS playback
* @param {Object} playerConfig - the player config
Expand All @@ -114,6 +123,24 @@ function checkNativeHlsSupport(playerConfig: Object): void {
}
}

/**
* Sets config option for native text track support
* @param {Object} playerConfig - the player config
* @returns {void}
*/
function checkNativeTextTracksSupport(playerConfig: Object): void {
if (isIos()) {
let useNativeTextTrack = Utils.Object.getPropertyPath(playerConfig, 'playback.useNativeTextTrack');
if (typeof useNativeTextTrack !== 'boolean') {
Utils.Object.mergeDeep(playerConfig, {
playback: {
useNativeTextTrack: true
}
});
}
}
}

/**
* Sets the storage config on the player config if certain conditions are met.
* @param {boolean} disableUserCache - Whether to disable the cache support.
Expand Down Expand Up @@ -162,7 +189,9 @@ export {
addKalturaPoster,
validateTargetId,
validateProvidersConfig,
setDefaultPlayerConfig,
checkNativeHlsSupport,
checkNativeTextTracksSupport,
isSafari,
isIos
};

0 comments on commit 3329366

Please sign in to comment.