Are you looking for a way to stream live or on-demand videos from your .NET MAUI app to a Google Cast device? In this post, you will learn how to find and connect to Chromecast devices in just 9 minutes. Ready to cast your videos?
Special thanks to our friend Gerald who shared with us this amazing article which helped me to integrate the Chromecast support into my .NET MAUI apps.
Required packages and project conditions
- Add the NuGet packages required to enable Google Cast on iOS and Android or edit the .csproj file and set them up there:
All
<ItemGroup>
<PackageReference Include="protobuf-net" Version="3.2.26" />
</ItemGroup>
Android
<ItemGroup Condition="'$(TargetFramework)' == 'net7.0-android'">
<PackageReference Include="Xamarin.GooglePlayServices.Cast" Version="121.1.0" />
<PackageReference Include="Xamarin.GooglePlayServices.Cast.Framework" Version="121.1.0" />
</ItemGroup>
iOS
<ItemGroup Condition="'$(TargetFramework)' == 'net7.0-ios'">
<PackageReference Include="Xamarin.Google.iOS.Cast" Version="4.7.0.1" />
</ItemGroup>
Required Workarounds
Well, let me share with you some news, the package Google Cast on NuGet is really cool, however, there are 2 issues with this package, and just to be clear I'm not blaming anybody, totally the opposite, I would like to thank you all people involved on those packages and their dependencies.
The Google Cast package has a dependency on the Zeroconf package, however, the Zeroconf package has an issue on iOS 16+, lucky us our friend Martin created a Pull-Request on the Zeroconf repository which fixes the iOS 16+ issues when discovering Chromecast devices within the network.
My recommendation is to download or clone the following Pull-Request and then add as reference this project into your .NET MAUI application. See the important note below:
*** IMPORTANT
Update the .csproj from the ZeroConf project and replace the following:
From
<TargetFrameworks>net6.0;netstandard2.0;net48;xamarinios10</TargetFrameworks>
To
<TargetFrameworks>net7.0;netstandard2.0;net7.0-ios</TargetFrameworks>
Finally, close the solution and re-open it, make sure there are not errors when trying to restore the packages and you will be set.
One Last Workaround
Since we are going to use the project we cloned from Zeroconf, the Google Cast NuGet package, won't work. So, we need to also clone the latest main version of the repository and convert the project to a .NET MAUI compatible class library or if you prefer, add all the source files from Google Cast repository, directly in your .NET MAUI project and that's all.
What's next?
From this point the .NET MAUI implementation is pretty much the same as our friend Gerald shared on his post, so I recommend you to take a look there, it is really easy to implement either directly on a Content Page or using MVVM.
Conclusion
Due to a missing compatibility of a dependency with iOS 16, we are forced to look back until we figure out the root cause of the issue. I think this is an opportunity to learn more and improve my skills. When the Zeroconf package updates to support iOS 16, we can just use the new version and it will replace the one used by the Google Cast package.
Thanks for reading! Follow me on Twitter @ivictorhugo
Top comments (3)
Have you had any luck casting with maui 8? c# doesn't seem to recognize the Xamarin.GooglePlayServices.Cast.Framework
Hello Joe,
I haven't test it in .NET MAUI 8, I hope to test it very soon and let you know the results :)
I did manage to get it to recognize the Cast nugget, but it seems to keep getting caught in some of internal self referencing loop. The error it throws is something along the lines of " .... cant to this because this is already defined in the array list...."