Skip to content

Commit

Permalink
Allow playback of demo content in Safari (#162)
Browse files Browse the repository at this point in the history
* Fixed a bug where playback of demo content was not possible in Safari because of issues with FairPlay

* Removed commented out code

* Linter fixes
  • Loading branch information
williamtfalchsquare authored Jul 25, 2024
1 parent 5688c8d commit 53f8b7b
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 1 deletion.
19 changes: 19 additions & 0 deletions packages/player/src/internal/handlers/load.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import shaka from 'shaka-player';

import type ShakaPlayer from 'player/shakaPlayer';

import type { MediaProduct } from '../../api/interfaces';
import * as Config from '../../config';
import { events } from '../../event-bus';
Expand Down Expand Up @@ -158,6 +162,21 @@ export async function load(
audioQuality,
);

if (player.name === 'shakaPlayer') {
const isFairPlaySupported =
await shaka.util.FairPlayUtils.isFairPlaySupported();

const isDemo = mediaProduct.productType === 'demo';
const config = {
streaming: {
preferNativeHls: isDemo ? false : isFairPlaySupported,
useNativeHlsForFairPlay: isDemo ? false : isFairPlaySupported,
},
};

(player as ShakaPlayer).updatePlayerConfig(config);
}

setActivePlayer(player);

return player.load(
Expand Down
20 changes: 20 additions & 0 deletions packages/player/src/internal/handlers/set-next.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/* eslint-disable complexity */
import shaka from 'shaka-player';

import type ShakaPlayer from 'player/shakaPlayer';

import type { MediaProduct } from '../../api/interfaces';
import * as Config from '../../config';
import { generateGUID } from '../../internal/helpers/generate-guid';
Expand Down Expand Up @@ -107,6 +112,21 @@ async function _setNext(
'trackId' in playbackInfo ? playbackInfo.audioQuality : undefined,
);

if (playerState.preloadPlayer.name === 'shakaPlayer') {
const isFairPlaySupported =
await shaka.util.FairPlayUtils.isFairPlaySupported();

const isDemo = mediaProduct.productType === 'demo';
const config = {
streaming: {
preferNativeHls: isDemo ? false : isFairPlaySupported,
useNativeHlsForFairPlay: isDemo ? false : isFairPlaySupported,
},
};

(playerState.preloadPlayer as ShakaPlayer).updatePlayerConfig(config);
}

const streamInfo = parseManifest(playbackInfo);

streamingSessionStore.saveStreamInfo(
Expand Down
13 changes: 12 additions & 1 deletion packages/player/src/player/shakaPlayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,8 @@ export default class ShakaPlayer extends BasePlayer {
* for triggering tracking events etc.
*/
// failureCallback() {},
useNativeHlsOnSafari: isFairPlaySupported,

useNativeHlsForFairPlay: isFairPlaySupported,
},
});

Expand Down Expand Up @@ -1077,6 +1078,16 @@ export default class ShakaPlayer extends BasePlayer {
}
}

updatePlayerConfig(config: Record<string, any>) {
if (this.#shakaInstanceOne) {
this.#shakaInstanceOne.configure(config);
}

if (this.#shakaInstanceTwo) {
this.#shakaInstanceTwo.configure(config);
}
}

get currentPlayer() {
return this.#currentPlayer;
}
Expand Down

0 comments on commit 53f8b7b

Please sign in to comment.