Skip to content

Commit

Permalink
fix: allow seeking after a stream has reached the end
Browse files Browse the repository at this point in the history
  • Loading branch information
oscnord committed Dec 12, 2023
1 parent 9bbb33e commit 4d5c7f6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ Does not support native HTML5 MSE controls (`<video controls>`). It works, but e

Does not support re-using the same video element.

Does not support restarting the video after end of stream has been reached.

## Usage

`npm install @eyevinn/media-event-filter`
Expand Down Expand Up @@ -316,6 +314,12 @@ A timeupdate event

Can not trigger before loaded.

### ended

The player has reached the end of a stream.

To allow restarting the stream after the end of stream has been reached set `allowResumeAfterEnded` to `true`.

## Contributing

Contributions to improve compatibility with or add support for different engines, tracking solutions, and browsers are welcome.
Expand Down
5 changes: 4 additions & 1 deletion src/media-event-filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ type TFilteredMediaEventCallback = (event: FilteredMediaEvent) => void;
type TMediaEventFilterOptions = {
videoElement: HTMLVideoElement;
callback: TFilteredMediaEventCallback;
allowResumeAfterEnded: boolean;
};

type TCallback = () => void;
Expand Down Expand Up @@ -101,6 +102,7 @@ export type TMediaEventFilter = {
export const getMediaEventFilter = ({
videoElement,
callback,
allowResumeAfterEnded = false,
}: TMediaEventFilterOptions): TMediaEventFilter => {
let ratechangeBufferTimeout: number | null = null;

Expand All @@ -114,7 +116,8 @@ export const getMediaEventFilter = ({
...initialState,
};

const isNotReady = (): boolean => state.loading || state.ended;
const isNotReady = (): boolean =>
allowResumeAfterEnded ? state.loading : state.loading || state.ended;

const onCanPlayThrough = (): void => {
if (!state.loading) {
Expand Down

0 comments on commit 4d5c7f6

Please sign in to comment.