Skip to content
This repository has been archived by the owner on May 17, 2024. It is now read-only.

Commit

Permalink
Fix dup maintrack (#46)
Browse files Browse the repository at this point in the history
* fix: prevent adding 2 main video tracks

* fix: add mixin types
  • Loading branch information
luwes authored Dec 17, 2023
1 parent 5bd0b91 commit c36a045
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
11 changes: 5 additions & 6 deletions hls-video-element.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import { CustomVideoElement } from 'custom-media-element';
import Hls from 'hls.js';

declare class HLSVideoElement extends CustomVideoElement {
type HlsVideoElementConstructor<T> = { new(): T };

export function HlsVideoMixin(superclass: any): HlsVideoElementConstructor<HLSVideoElement>;

export class HLSVideoElement extends CustomVideoElement {
/**
* The current instance of the HLS.js library.
*
Expand All @@ -18,11 +22,6 @@ declare class HLSVideoElement extends CustomVideoElement {
*/
attributeChangedCallback(attrName: string, oldValue: any, newValue: any): void;

/**
* Loads the HLS.js instance and attach it to the video element.
*/
load(): Promise<void>;

/**
* Unloads the HLS.js instance and detaches it from the video element.
*/
Expand Down
9 changes: 7 additions & 2 deletions hls-video-element.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,13 @@ const HlsVideoMixin = (superclass) => {
this.api.on(Hls.Events.MANIFEST_PARSED, (event, data) => {
removeAllMediaTracks();

const videoTrack = this.addVideoTrack('main');
videoTrack.selected = true;
let videoTrack = this.videoTracks.getTrackById('main');

if (!videoTrack) {
videoTrack = this.addVideoTrack('main');
videoTrack.id = 'main';
videoTrack.selected = true;
}

for (const [id, level] of data.levels.entries()) {
const videoRendition = videoTrack.addRendition(
Expand Down

0 comments on commit c36a045

Please sign in to comment.