Skip to content

Commit

Permalink
fix(FEC-7896): endless spinner appears right after changing audio tra…
Browse files Browse the repository at this point in the history
…ck in IE and Edge (#47)

Handling a situation after audio track is changed, only in IE and Edge.
If a waiting event is sent, we send playing event.
  • Loading branch information
odedhutzler authored and Dan Ziv committed Feb 11, 2018
1 parent b405683 commit ce4b28d
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion src/hls-adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import Hlsjs from 'hls.js'
import DefaultConfig from './default-config'
import {HlsJsErrorMap, type ErrorDetailsType} from "./errors"
import {BaseMediaSourceAdapter, Utils, Error} from 'playkit-js'
import {BaseMediaSourceAdapter, Utils, Error, Env} from 'playkit-js'
import {Track, VideoTrack, AudioTrack, TextTrack} from 'playkit-js'

/**
Expand Down Expand Up @@ -449,6 +449,25 @@ export default class HlsAdapter extends BaseMediaSourceAdapter {
});
HlsAdapter._logger.debug('Audio track changed', audioTrack);
this._onTrackChanged(audioTrack);
this._handleWaitingUponAudioTrackSwitch();
}

/**
* Trigger a playing event whenever an audio track is changed & time_update event is fired.
* This align Edge and IE behaviour to other browsers. When an audio track changed in IE & Edge, they trigger
* waiting event but not playing event.
* @returns {void}
* @private
*/
_handleWaitingUponAudioTrackSwitch(): void {
const affectedBrowsers = ['IE', 'Edge'];
if (affectedBrowsers.includes(Env.browser.name)) {
const timeUpdateListener = () => {
this._trigger(BaseMediaSourceAdapter.Html5Events.PLAYING);
this._videoElement.removeEventListener(BaseMediaSourceAdapter.Html5Events.TIME_UPDATE, timeUpdateListener);
}
this._videoElement.addEventListener(BaseMediaSourceAdapter.Html5Events.TIME_UPDATE, timeUpdateListener)
}
}

/**
Expand Down

0 comments on commit ce4b28d

Please sign in to comment.