Skip to content

Commit

Permalink
Rework native player reset state (#199)
Browse files Browse the repository at this point in the history
* Bump version and update changelog

* Fix unstable reset states in native player by deriving state from session ids instead of setting a flag.
  • Loading branch information
enjikaka authored Sep 25, 2024
1 parent e883282 commit ac1d3c4
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions packages/player/src/player/nativePlayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,6 @@ export default class NativePlayer extends BasePlayer {
*/
#duration!: number;

#isReset = true;

#player!: NativePlayerComponentInterface;

#preloadedLoadPayload: LoadPayload | undefined;
Expand Down Expand Up @@ -283,9 +281,7 @@ export default class NativePlayer extends BasePlayer {
this.currentTime = payload.assetPosition;
this.startAssetPosition = payload.assetPosition;

// Ensure reset and set reset to false since we're loading anew.
await this.reset();
this.#isReset = false;

const { assetPosition, mediaProduct, playbackInfo, streamInfo } = payload;
const { securityToken, streamFormat, streamUrl } = streamInfo;
Expand Down Expand Up @@ -386,6 +382,10 @@ export default class NativePlayer extends BasePlayer {

if (streamFormat) {
this.#player.preload(streamUrl, streamFormat, securityToken);

if (!this.isActivePlayer) {
this.#player.pause();
}
} else {
console.error('Stream format undefined for preload.');
}
Expand All @@ -405,7 +405,6 @@ export default class NativePlayer extends BasePlayer {
});

this.#preloadedLoadPayload = payload;
this.#isReset = false;
}

pause() {
Expand Down Expand Up @@ -531,7 +530,7 @@ export default class NativePlayer extends BasePlayer {
async reset(
{ keepPreload }: { keepPreload: boolean } = { keepPreload: false },
) {
if (this.#isReset) {
if (this.currentStreamingSessionId === undefined) {
return;
}

Expand All @@ -556,7 +555,6 @@ export default class NativePlayer extends BasePlayer {
}

this.playbackState = 'IDLE';
this.#isReset = true;
}

async seek(seconds: number) {
Expand Down

0 comments on commit ac1d3c4

Please sign in to comment.