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?
- Add the NuGet packages required to enable Google Cast on iOS and Android or edit the .csproj file and set them up there:
<ItemGroup> <PackageReference Include="protobuf-net" Version="3.2.26" /> </ItemGroup>
<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>
<ItemGroup Condition="'$(TargetFramework)' == 'net7.0-ios'"> <PackageReference Include="Xamarin.Google.iOS.Cast" Version="188.8.131.52" /> </ItemGroup>
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:
Update the .csproj from the ZeroConf project and replace the following:
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.
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.
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.
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