Skip to content

Commit

Permalink
chore: Remove duplicated code in MediaSourceEngine (#7393)
Browse files Browse the repository at this point in the history
  • Loading branch information
tykus160 authored Oct 3, 2024
1 parent 96da45a commit 7f8b4c8
Showing 1 changed file with 19 additions and 30 deletions.
49 changes: 19 additions & 30 deletions lib/media/media_source_engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ shaka.media.MediaSourceEngine = class {
/** @private {boolean} */
this.playbackHasBegun_ = false;

/** @private {(MediaSource|ManagedMediaSource)} */
/** @private {MediaSource} */
this.mediaSource_ = this.createMediaSource(this.mediaSourceOpen_);

/** @private {boolean} */
Expand Down Expand Up @@ -179,13 +179,16 @@ shaka.media.MediaSourceEngine = class {
* Replaced by unit tests.
*
* @param {!shaka.util.PublicPromise} p
* @return {!(MediaSource|ManagedMediaSource)}
* @return {!MediaSource}
*/
createMediaSource(p) {
/** @type {!MediaSource} */
let mediaSource;

if (window.ManagedMediaSource) {
this.video_.disableRemotePlayback = true;

const mediaSource = new ManagedMediaSource();
mediaSource = new ManagedMediaSource();

this.eventManager_.listen(
mediaSource, 'startstreaming', () => {
Expand All @@ -196,39 +199,25 @@ shaka.media.MediaSourceEngine = class {
mediaSource, 'endstreaming', () => {
this.streamingAllowed_ = false;
});

this.eventManager_.listenOnce(
mediaSource, 'sourceopen', () => this.onSourceOpen_(p));

// Correctly set when playback has begun.
this.eventManager_.listenOnce(this.video_, 'playing', () => {
this.playbackHasBegun_ = true;
});

this.url_ = shaka.media.MediaSourceEngine.createObjectURL(mediaSource);

this.video_.src = this.url_;

return mediaSource;
} else {
const mediaSource = new MediaSource();
mediaSource = new MediaSource();
}

// Set up MediaSource on the video element.
this.eventManager_.listenOnce(
mediaSource, 'sourceopen', () => this.onSourceOpen_(p));
// Set up MediaSource on the video element.
this.eventManager_.listenOnce(
mediaSource, 'sourceopen', () => this.onSourceOpen_(p));

// Correctly set when playback has begun.
this.eventManager_.listenOnce(this.video_, 'playing', () => {
this.playbackHasBegun_ = true;
});
// Correctly set when playback has begun.
this.eventManager_.listenOnce(this.video_, 'playing', () => {
this.playbackHasBegun_ = true;
});

// Store the object URL for releasing it later.
this.url_ = shaka.media.MediaSourceEngine.createObjectURL(mediaSource);
// Store the object URL for releasing it later.
this.url_ = shaka.media.MediaSourceEngine.createObjectURL(mediaSource);

this.video_.src = this.url_;
this.video_.src = this.url_;

return mediaSource;
}
return mediaSource;
}

/**
Expand Down

0 comments on commit 7f8b4c8

Please sign in to comment.