setMedia(media) {
    // Alias
    const PatchedMediaKeysApple = shaka.polyfill.PatchedMediaKeysApple;

    // Remove any old listeners.
    this.eventManager_.removeAll();

    // It is valid for media to be null; null is used to flag that event
    // handlers need to be cleaned up.
    if (!media) {
      return Promise.resolve();
    }

    // Intercept and translate these prefixed EME events.
    this.eventManager_.listen(media, 'webkitneedkey',
    /** @type {shaka.util.EventManager.ListenerType} */
        (PatchedMediaKeysApple.onWebkitNeedKey_));

    // Wrap native HTMLMediaElement.webkitSetMediaKeys with a Promise.
    try {
      // Some browsers require that readyState >=1 before mediaKeys can be
      // set, so check this and wait for loadedmetadata if we are not in the
      // correct state
      shaka.util.MediaReadyState.waitForReadyState(media,
          HTMLMediaElement.HAVE_METADATA,
          this.eventManager_, () => {
            media.webkitSetMediaKeys(this.nativeMediaKeys_);
          });

      return Promise.resolve();
    } catch (exception) {
      return Promise.reject(exception);
    }
  }
@param {HTMLMediaElement} media
@protected
@return {!Promise}