getContentId: function (emeOptions, initData) {
    console.log("initData", initData);
    // const pattern = "skd://";
    // const idx = initData.indexOf(pattern);
    // let parameters = "";

    // if (idx > -1) {
    //   parameters = initData.substring(idx + pattern.length);
    //   parameters = parameters.replace(/assetid/gi, "assetId");
    //   parameters = parameters.replace(/variantid/gi, "variantId");
    // }
    // console.log("parameters", parameters);
    // return parameters;
    return initData;
  }

  getContentId: (emeOptions, initData) => initData,
  getCertificate: function (emeOptions, callback) {
    videojs.xhr(
      {
        url: drmConfig.fairplay.certificateUrl,
        method: "GET",
        headers: {
          // 'x-dt-custom-data': 'eyJ1c2VySWQiOiAicHVyY2hhc2UiLCAibWVyY2hhbnQiOiAiY2xpZW50X2RldiIsICJzZXNzaW9uSWQiOiAiZGVmYXVsdCJ9',
          // 'Pragma': 'no-cache',
          // 'Cache-Control': 'no-cache',
          // 'Content-Type': 'text/xml; charset=utf-8'
        },
        // responseType: "application/x-x509-ca-cert",
        responseType: "arraybuffer",
      },
      (err, response, responseBody) => {
        callback(null, new Uint8Array(responseBody));
      }
    );
  },
  getLicense: function (emeOptions, contentId, keyMessage, callback) {
    // let binary = '';
    // const len = keyMessage.length;
    // for (let i = 0; i < len; i++) {
    //   binary += String.fromCharCode(keyMessage[i]);
    // }
    // console.log("binary", btoa(binary));

    videojs.xhr(
      {
        url: drmConfig.fairplay.url,
        method: "POST",
        responseType: "text",
        body: keyMessage,
        // body:
        //   "spc=" +
        //   btoa({
        //     spc: keyMessage.toBase64(),
        //     keyId: encodeURIComponent(contentId),
        //     assetId: encodeURIComponent("Fairplay-Test"),
        //   }),
        // body: 'spc=' + keyMessage.toBase64() + '&assetId=' + encodeURIComponent('Fairplay-Test'),
        headers: {
          ...drmConfig.fairplay.licenseHeaders,
          // "Content-Type": "application/x-www-form-urlencoded",
          // "x-custom-data":
          //   "eyJ1c2VySWQiOiJyZW50YWwxIiwic2Vzc2lvbklkIjoicDAiLCJtZXJjaGFudCI6IjQ2YzdkNmZiLWYyOTktNDUwMS1hNDc0LTBhZWRjMjZlYTBhMiJ9",
        },
      },
      (err, response, responseBody) => {
        let rawLicenseString = atob(responseBody);
        let data = new Uint8Array(rawLicenseString.length);
        for (let i = 0; i < rawLicenseString.length; ++i) {
          data[i] = rawLicenseString.charCodeAt(i);
        }
        let key = data.buffer;
        callback(null, key);
      }
    );
  },
  
          <svg class="settings-arrow" viewBox="0 0 24 24" fill="currentColor">
          <path d="M15.41 7.41L14 6l-6 6 6 6 1.41-1.41L10.83 12z"/>
        </svg>

          updateSubtitlesFromShaka(textTracksData) {
    try {
      console.log("Updating subtitles from Shaka Player data:", textTracksData);

      if (textTracksData && textTracksData.length > 0) {
        this.subtitles = textTracksData
          .filter(
            (track) =>
              track.kind === "captions" ||
              track.kind === "subtitles" ||
              track.kind === "subtitle"
          )
          .map((track, index) => ({
            id: track.id,
            language: track.language,
            label: track.label || track.language || `Subtitle ${index + 1}`,
            kind: track.kind,
            index: index,
            shakaTrack: track,
          }));

        console.log("Available subtitles from Shaka Player:", this.subtitles);

        // Update current subtitle based on active track
        this.updateCurrentSubtitle();
      }
    } catch (error) {
      console.warn("Could not update subtitles from Shaka Player:", error);
    }
  }