Skip to content

Commit

Permalink
player/mse-player: Use PlayerEngineDedicatedThread if supported and r…
Browse files Browse the repository at this point in the history
…equired enableWorkerForMSE
  • Loading branch information
xqq committed Oct 8, 2023
1 parent 3aeffa8 commit a62d41a
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/player/mse-player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@
* limitations under the License.
*/

import Log from '../utils/logger';
import MediaInfo from '../core/media-info';
import PlayerEngine from './player-engine';
import PlayerEngineMainThread from './player-engine-main-thread';
import PlayerEngineDedicatedThread from './player-engine-dedicated-thread';
import {InvalidArgumentException} from '../utils/exception';
import MediaInfo from '../core/media-info';

class MSEPlayer {

Expand All @@ -39,8 +41,17 @@ class MSEPlayer {
throw new InvalidArgumentException('MSEPlayer requires an mpegts/m2ts/flv MediaDataSource input!');
}

this._media_element = null;
this._player_engine = new PlayerEngineMainThread(mediaDataSource, config);
if (config && config.enableWorkerForMSE && PlayerEngineDedicatedThread.isSupported()) {
try {
this._player_engine = new PlayerEngineDedicatedThread(mediaDataSource, config);
} catch (error) {
Log.e(this.TAG,
'Error while initializing PlayerEngineDedicatedThread, fallback to PlayerEngineMainThread');
this._player_engine = new PlayerEngineMainThread(mediaDataSource, config);
}
} else {
this._player_engine = new PlayerEngineMainThread(mediaDataSource, config);
}
}

public destroy(): void {
Expand Down

0 comments on commit a62d41a

Please sign in to comment.