How to direct to a custom Receiver App while casting?

Hi there,

Things are working fine with casting in Flutter with the bitmovin_player 0.2.0 package. Except that I don’t find the right way to direct the cast to a custom Receiver App.
All settings in the receiver app are okay, like the the PackageName for Android. (Testing Android right now).

Here is the code we have:

final _playerViewKey = GlobalKey<PlayerViewState>();

late Player _bitmovinplayer = Player();

late SourceConfig _SourceConfig;

late BitmovinCastManagerOptions options = const BitmovinCastManagerOptions(
  applicationId: 'XXXXXX'
);

initBitmovinPlayer(String videourl, String title)
{
    Future.delayed(const Duration(milliseconds: 100), () {
      setState(() {
        _bitmovinplayer = Player(
          config: const PlayerConfig(
            key: "xxxxx",
            playbackConfig: PlaybackConfig(
              isAutoplayEnabled: false,
              isMuted: false,
            )
          ),
        );
        _SourceConfig = SourceConfig(
          url: videourl,
          type: SourceType.progressive,
          title: "$title",
        );
      });
    });
      
    Future.delayed(const Duration(milliseconds: 200), () {
    setState(() {
        _bitmovinplayer.loadSourceConfig(_SourceConfig);
      });
    });
}

Flexible(
    fit: FlexFit.loose,
    child: Center(
      child: 
      AspectRatio(
        aspectRatio: 16 / 9,
        child: PlayerView(
          player: _bitmovinplayer,
          key: _playerViewKey
        ),
      ),
    )
  ),

The question is: How to fit in:

await BitmovinCastManager.initialize(options: options);

Best, Peter

Hi Peter!

Initializing the cast manager, creating the player and loading a source are all async operations.

Ideally, the await BitmovinCastManager.initialize(options: options) is done before the player instance is created. I suggest to have a look at our casting example application that solves this by using final Future<_PlayerState> _playerState;, which provides access to the initialized cast manager and player, in combination with FutureBuilder.

Using an approach like this would also allow to remove the Future.delayed usages from your example which could easily become the source of race conditions in the future.

It would also be possible to initialize the cast manager on application start-up already and inject the instance of BitmovinCastManager, as returned by await BitmovinCastManager.initialize(options: options);, to each component or page that needs it.

Best,
Mario