Google cast for android using bitmovin-player-react-native

Hello, I have a strange problem with casting on android. First, cast button sometimes is not even displayed near target device. If cast is connected, app is closing and there is no way to stop the casting, and start with another video. What could be the reason for such strange behaviour? I’ve made all the necessary changes in build.gradle and AndroidManifest.xml files. And here is a code setting up a cast source from player

if (isAndroid) {
BitmovinCastManager.initialize();
BitmovinCastManager.updateContext();
}

useEffect(() => {
  if (isAndroid) {
    BitmovinCastManager.updateContext();
  }
}, [file]);


useFocusEffect(
  useCallback(() => {
    const source = new Source({
      url: file,
      type: !isAndroid ? SourceType.HLS : SourceType.DASH,
      title: title,
      poster: poster,
      metadata: { platform: Platform.OS },
    });

    source.remoteControl = {
      castSourceConfig: {
        url: file,
        type: SourceType.DASH,
        title: title,
      },
    };
    player.loadSource(source);
    return () => {
      player.destroy();
    };
  }, [player, file]),
);

Please, help me to make it work stable, also here is a code for a PlayerView, maybe I need to handle some props events here?

        <PlayerView
          style={styles.playerView}
          player={player}
          onReady={onReady}
          onTimeChanged={handleTimeChanged}
          onPlaybackFinished={handleEnd}
          onPlay={handleTogglePlay}
          onPaused={handleTogglePlay}
        />

And also here is a player setup using usePlayer

const player = usePlayer({
  remoteControlConfig: {
    isCastEnabled: true,
  },
  playbackConfig: {
    isAutoplayEnabled: false,
    isMuted: appSettings?.default_no_music ?? false,
    isBackgroundPlaybackEnabled: true,
  },
});

Hi @mykola_parfenov!

Would it be possible to share a project where the issue can be reproduced with us? That would be the easiest way to find the issue.

If that is not possible, we’ll need some more details regarding your setup:

  • React Native version
  • Bitmovin Player version
  • com.google.android.gms:play-services-cast-framework version in your app’s build.gradle
  • androidx.mediarouter:mediarouter version in your app’s build.gradle
  • Android version of the device where you are reproducing this issue

I would also be interested to know what your stream looks like since I see a variable name file in your code, are you trying to cast a local file? To exclude the possibility of a stream issue, are you able to cast with: https://dash.akamaized.net/akamai/bbb_30fps/bbb_30fps.mpd?

Greetings,
Žiga Vehovec

Hi, Žiga Vehovec!

Thank you for a reply, here is answers on your questions:

1)“react-native”: “0.70.6”,
2)“bitmovin-player-react-native”: “^0.17.0”,
3)implementation(“com.google.android.gms:play-services-cast-framework:21.3.0”)
4)implementation(“androidx.mediarouter:mediarouter:1.3.1”)

  1. It can be different since there is multiple testers but I think usually it is Android 13-14.

I’m trying to stream an .mpd file

Hi @mykola_parfenov!

Thanks for the provided information. I don’t see any issues within your dependencies, nor the setup you provided.
I can see a potential problem with the fact that you are trying to stream a local file directly though.
It’s not possible to directly cast a local MPD file, you need a server implementation that serves that file, so that the casting receiver can access it.

Have you tried to cast the stream that I provided in the last reply? Does casting work as expected with it?