Skip to content

Commit

Permalink
When loadSource is called, do not detach and reattach media unless th…
Browse files Browse the repository at this point in the history
…e URL has changed, and source buffer types are set

Resolves #3732
  • Loading branch information
Rob Walch committed Apr 12, 2021
1 parent ed21c75 commit c40420f
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 30 deletions.
7 changes: 7 additions & 0 deletions src/controller/buffer-controller.ts
Expand Up @@ -67,6 +67,13 @@ export default class BufferController implements ComponentAPI {
this.registerListeners();
}

public hasSourceTypes(): boolean {
return (
this.getSourceBufferTypes().length > 0 ||
Object.keys(this.pendingTracks).length > 0
);
}

public destroy() {
this.unregisterListeners();
this.details = null;
Expand Down
75 changes: 45 additions & 30 deletions src/hls.ts
@@ -1,32 +1,29 @@
import * as URLToolkit from 'url-toolkit';

import { ErrorTypes, ErrorDetails } from './errors';

import PlaylistLoader from './loader/playlist-loader';
import KeyLoader from './loader/key-loader';

import ID3TrackController from './controller/id3-track-controller';
import LatencyController from './controller/latency-controller';
import LevelController from './controller/level-controller';
import { FragmentTracker } from './controller/fragment-tracker';
import StreamController from './controller/stream-controller';
import LevelController from './controller/level-controller';

import { isSupported } from './is-supported';
import { logger, enableLogs } from './utils/logger';
import { enableStreamingMode, hlsDefaultConfig, mergeConfig } from './config';
import type { HlsConfig } from './config';
import { Events } from './events';
import { EventEmitter } from 'eventemitter3';
import { Level } from './types/level';
import type { MediaPlaylist } from './types/media-playlist';
import AudioTrackController from './controller/audio-track-controller';
import SubtitleTrackController from './controller/subtitle-track-controller';
import ID3TrackController from './controller/id3-track-controller';
import EMEController from './controller/eme-controller';
import CapLevelController from './controller/cap-level-controller';
import AbrController from './controller/abr-controller';
import LatencyController from './controller/latency-controller';
import { ComponentAPI, NetworkComponentAPI } from './types/component-api';
import { Events } from './events';
import { ErrorTypes, ErrorDetails } from './errors';
import type { HlsEventEmitter, HlsListeners } from './events';
import { Fragment } from './loader/fragment';
import type AudioTrackController from './controller/audio-track-controller';
import type AbrController from './controller/abr-controller';
import type BufferController from './controller/buffer-controller';
import type CapLevelController from './controller/cap-level-controller';
import type EMEController from './controller/eme-controller';
import type SubtitleTrackController from './controller/subtitle-track-controller';
import type { ComponentAPI, NetworkComponentAPI } from './types/component-api';
import type { MediaPlaylist } from './types/media-playlist';
import type { HlsConfig } from './config';
import type { Level } from './types/level';
import type { Fragment } from './loader/fragment';

/**
* @module Hls
Expand All @@ -45,6 +42,7 @@ export default class Hls implements HlsEventEmitter {
private _emitter: HlsEventEmitter = new EventEmitter();
private _autoLevelCapping: number;
private abrController: AbrController;
private bufferController: BufferController;
private capLevelController: CapLevelController;
private latencyController: LatencyController;
private levelController: LevelController;
Expand Down Expand Up @@ -109,12 +107,20 @@ export default class Hls implements HlsEventEmitter {
}

// core controllers and network loaders
const abrController = (this.abrController = new config.abrController(this)); // eslint-disable-line new-cap
const bufferController = new config.bufferController(this); // eslint-disable-line new-cap
const capLevelController = (this.capLevelController = new config.capLevelController(
const {
abrController: ConfigAbrController,
bufferController: ConfigBufferController,
capLevelController: ConfigCapLevelController,
fpsController: ConfigFpsController,
} = config;
const abrController = (this.abrController = new ConfigAbrController(this));
const bufferController = (this.bufferController = new ConfigBufferController(
this
)); // eslint-disable-line new-cap
const fpsController = new config.fpsController(this); // eslint-disable-line new-cap
));
const capLevelController = (this.capLevelController = new ConfigCapLevelController(
this
));
const fpsController = new ConfigFpsController(this);
const playListLoader = new PlaylistLoader(this);
const keyLoader = new KeyLoader(this);
const id3TrackController = new ID3TrackController(this);
Expand Down Expand Up @@ -316,15 +322,24 @@ export default class Hls implements HlsEventEmitter {
loadSource(url: string) {
this.stopLoad();
const media = this.media;
if (media && this.url) {
const loadedSource = this.url;
const loadingSource = (this.url = URLToolkit.buildAbsoluteURL(
self.location.href,
url,
{
alwaysNormalize: true,
}
));
logger.log(`loadSource:${loadingSource}`);
if (
media &&
loadedSource &&
loadedSource !== loadingSource &&
this.bufferController.hasSourceTypes()
) {
this.detachMedia();
this.attachMedia(media);
}
url = URLToolkit.buildAbsoluteURL(self.location.href, url, {
alwaysNormalize: true,
});
logger.log(`loadSource:${url}`);
this.url = url;
// when attaching to a source URL, trigger a playlist load
this.trigger(Events.MANIFEST_LOADING, { url: url });
}
Expand Down

0 comments on commit c40420f

Please sign in to comment.