Skip to content

Commit

Permalink
feat(player): Added stop method to pause properly live streaming
Browse files Browse the repository at this point in the history
  • Loading branch information
rafa8626 committed Aug 28, 2022
1 parent 028c218 commit 9a811b9
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 1 deletion.
7 changes: 7 additions & 0 deletions dist/esm/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,13 @@ class Player {
__classPrivateFieldGet(this, _Player_media, "f").pause();
}
}
stop() {
this.pause();
if (__classPrivateFieldGet(this, _Player_media, "f")) {
__classPrivateFieldGet(this, _Player_media, "f").currentTime = 0;
this.src = [{ src: '', type: 'video/mp4' }];
}
}
destroy() {
var _a;
if (__classPrivateFieldGet(this, _Player_adsInstance, "f")) {
Expand Down
13 changes: 13 additions & 0 deletions dist/openplayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -7982,6 +7982,19 @@ var Player = function () {
player_classPrivateFieldGet(this, _Player_media, "f").pause();
}
}
}, {
key: "stop",
value: function stop() {
this.pause();

if (player_classPrivateFieldGet(this, _Player_media, "f")) {
player_classPrivateFieldGet(this, _Player_media, "f").currentTime = 0;
this.src = [{
src: '',
type: 'video/mp4'
}];
}
}
}, {
key: "destroy",
value: function destroy() {
Expand Down
2 changes: 1 addition & 1 deletion dist/openplayer.min.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ The methods supported by the OpenPlayerJS instance are:
| `addElement` | Append a new HTML element to the video/audio tag with the possibility dispatch a custom callback so it gets registered/loaded in the player, via `controlschanged` event. It requires an object with `icon` URL/path, `id` for the button, its `position` and common callbacks to dispatch an action. For more details on how to create a custom element, read [Add Control](customize.md#add-control). |
| `addControl` | Shorthand method to generate a custom element of type `button`. For more details on how to create a custom button, read [Add Control](customize.md#add-control). |
| `removeControl` | Remove a control from the control bar using the name indicated in the `layers` configuration (`play`, `progress`, `time`, etc.); it can be a default element or a custom control. |
| `stop` | Pauses the media being played, sets the current time to zero, and sets the source as empty (useful when dealing with live streamings, to avoid the continuous download of chunks). |
| `destroy` | Destroy OpenMedia Player instance (including all events associated) and return the `video/audio` tag to its original state. |
| `getAd` | Retrieve an instance of the `Ads` object. More information at [Ad instance](api.md#ad-instance) |
| `getMedia` | Retrieve an instance of the `Media` object. More information at [Media instance](api.md#media-instance) |
Expand Down
9 changes: 9 additions & 0 deletions src/js/player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,15 @@ class Player {
}
}

stop(): void {
this.pause();

if (this.#media) {
this.#media.currentTime = 0;
this.src = [{ src: '', type: 'video/mp4' }];
}
}

destroy(): void {
if (this.#adsInstance) {
this.#adsInstance.pause();
Expand Down
1 change: 1 addition & 0 deletions types/player.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ declare class Player {
load(): Promise<void>;
play(): Promise<void>;
pause(): void;
stop(): void;
destroy(): void;
getContainer(): HTMLElement;
getControls(): Controls;
Expand Down

0 comments on commit 9a811b9

Please sign in to comment.