Skip to content

Subtitles not showing on Android #81

@hrithvik123

Description

@hrithvik123

On my android app, the subtitles don't work. Here's the logcat logs that include the subtitleOptions:

2025-05-19 22:20:04.266 22293-22293 Capacitor               app.iptvweb                          V  callback: 66783848, pluginId: MediaPlayer, methodName: create, methodData: {"url":"https:\/\/crankit.xyz\/movie\/Hrithvik2024\/rcSxkhxQpt\/395786.mkv","playerId":"video-player-4n4zcgo","android":{"enablePiP":true,"enableBackgroundPlay":true,"automaticallyEnterPiP":true},"extra":{"title":"Iron Man","subtitle":"","showControls":true,"autoPlayWhenReady":false,"poster":"https:\/\/image.tmdb.org\/t\/p\/w1280\/cyecB7godJ6kNHGONFjUyVN9OX5.jpg","subtitles":{"url":"https:\/\/www.opensubtitles.com\/download\/B36435EA497C64EB453133F788E9FD3CD533F8F7986759F35C7A13B116E7E6F760F2F21A03B43E66C2E43F1BFCAC334536C0CDC145EDC2AE6BF0F99F28687F5EAD266331D9EB998FB9BF9C74269EF37DD956DCB1458C356B98481D1B7A2C5BE55D16682C14DC16CEE08AA2EB502E940FE8E7143FF4FBB1015C39DE0ABD7F28F33937D7B5ADA2CF7878A64DB577565FA7D80F83077B7B7CFCAD61E997D026317B162913FBA6E19CF1E997CCF8F6529F4A8E31B85D6D709CDA8BB493409EA699D225BCB8F9D2671E8445B399BCF753CFCE472F3777B8523D6620369F4D8293E533E1635E0F1536FFB9511C580B801108C9601A0790FE6926B00D35BC230DFC44BDB4F572C0578DA65AA88A1F4B1E61C5364C77A2560028C6B5CA2DFEF25DAA578E\/subfile\/bestdivx-iman-cd1.en.webvtt","options":{"language":"en","foregroundColor":"#FFFFFF","backgroundColor":"#00000080","fontSize":18}}}}

Here's the calling code in my react app:

const initializeNativePlayer = async (seektime?: number) => {
      if (isInitialized) return;
      if (stream) {
        let subtitleOptions = undefined;

        if (tmdbId && type !== CategoryType.LIVE) {
          try {
            const response = await apiClient.GetSubtitlesForMedia(
              tmdbId.toString()
            );

            if (response.data?.success && response.data?.data) {
              const preferredSubtitle =
                response.data.data.find(
                  (sub) =>
                    sub.language.toLowerCase() === "english" ||
                    sub.language.toLowerCase() === "en"
                ) || response.data.data[0];

              subtitleOptions = {
                url: preferredSubtitle.downloadUrl,
                options: {
                  language: preferredSubtitle.language,
                  foregroundColor: "#FFFFFF",
                  backgroundColor: "#00000080",
                  fontSize: 18,
                },
              };
            }
          } catch (error) {
            console.error("Failed to fetch subtitles:", error);
          }
        }

        try {
          await MediaPlayer.create({
            url: stream,
            playerId,
            android: {
              enablePiP: true,
              enableBackgroundPlay: true,
              automaticallyEnterPiP: true,
            },
            extra: {
              title,
              subtitle: smallTitle || "",
              showControls: true,
              autoPlayWhenReady: false,
              poster: poster ?? undefined,
              subtitles: subtitleOptions,
            },
          });

          if (!listenersAdded.current) {
            attachListeners(seektime);
            listenersAdded.current = true;
          }

          setIsInitialized(true);
        } catch (error) {
          console.error("Error initializing native player:", error);
        }
      }
    };

Am I missing something in my implementation?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions