createMediaSource(p) {
    this.streamingAllowed_ = true;

    /** @type {!MediaSource} */
    let mediaSource;

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

      mediaSource = new ManagedMediaSource();

      this.eventManager_.listen(
          mediaSource, 'startstreaming', () => {
            shaka.log.info('MMS startstreaming');
            this.streamingAllowed_ = true;
          });

      this.eventManager_.listen(
          mediaSource, 'endstreaming', () => {
            shaka.log.info('MMS endstreaming');
            this.streamingAllowed_ = false;
          });
    } else {
      mediaSource = new MediaSource();
    }

    // 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;
    });

    // Store the object URL for releasing it later.
    this.url_ = shaka.media.MediaSourceEngine.createObjectURL(mediaSource);
    if (this.config_.useSourceElements) {
      this.video_.removeAttribute('src');
      if (this.source_) {
        this.video_.removeChild(this.source_);
      }
      if (this.secondarySource_) {
        this.video_.removeChild(this.secondarySource_);
      }
      this.source_ = shaka.util.Dom.createSourceElement(this.url_);
      this.video_.appendChild(this.source_);
      if (this.secondarySource_) {
        this.video_.appendChild(this.secondarySource_);
      }
      this.video_.load();
    } else {
      this.video_.src = this.url_;
    }

    return mediaSource;
  }
Create a MediaSource object, attach it to the video element, and return it.
Resolves the given promise when the MediaSource is ready.

Replaced by unit tests.

@param {!shaka.util.PublicPromise} p
@return {!MediaSource}