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

**URL:** <https://community.bitmovin.com/t/google-cast-for-android-using-bitmovin-player-react-native/2696>\
**Category:** Support\
**Tags:** bitmovin-player, android, bitmovin\
**Created:** [March 8, 2024, 5:07am UTC](https://community.bitmovin.com/t/google-cast-for-android-using-bitmovin-player-react-native/2696 "2024-03-08T05:07:30Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![mykola\_parfenov](https://avatars.discourse-cdn.com/v4/letter/m/a587f6/32.png) [@mykola\_parfenov](https://community.bitmovin.com/u/mykola_parfenov)\
**Post date:** [March 8, 2024, 5:07am UTC](https://community.bitmovin.com/t/google-cast-for-android-using-bitmovin-player-react-native/2696/1 "2024-03-08T05:07:30Z")

</div>

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

```

---

<div class="post-metadata">

**Author:** ![ziga.vehovec](https://sea1.discourse-cdn.com/flex015/user_avatar/community.bitmovin.com/ziga.vehovec/32/472_2.png) [@ziga.vehovec](https://community.bitmovin.com/u/ziga.vehovec)\
**Post date:** [March 12, 2024, 4:05pm UTC](https://community.bitmovin.com/t/google-cast-for-android-using-bitmovin-player-react-native/2696/2 "2024-03-12T16:05:22Z")

</div>

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](https://dash.akamaized.net/akamai/bbb_30fps/bbb_30fps.mpd)?

Greetings,  
Žiga Vehovec

---

<div class="post-metadata">

**Author:** ![mykola\_parfenov](https://avatars.discourse-cdn.com/v4/letter/m/a587f6/32.png) [@mykola\_parfenov](https://community.bitmovin.com/u/mykola_parfenov)\
**Post date:** [March 14, 2024, 11:54pm UTC](https://community.bitmovin.com/t/google-cast-for-android-using-bitmovin-player-react-native/2696/3 "2024-03-14T23:54:59Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ziga.vehovec](https://sea1.discourse-cdn.com/flex015/user_avatar/community.bitmovin.com/ziga.vehovec/32/472_2.png) [@ziga.vehovec](https://community.bitmovin.com/u/ziga.vehovec)\
**Post date:** [March 18, 2024, 10:58am UTC](https://community.bitmovin.com/t/google-cast-for-android-using-bitmovin-player-react-native/2696/4 "2024-03-18T10:58:24Z")

</div>

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?
