Google Chromecast in .NET MAUI
Tags: ios, android, dotnetmaui, dotnet
Published: 2023-08-17 20:39:47

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](https://www.youtube.com/@jfversluis) who shared with us this amazing [article](https://blog.verslu.is/xamarin-forms-xamarin/google-chromecast-app/) 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**
```xml
<ItemGroup>
    <PackageReference Include="protobuf-net" Version="3.2.26" />
</ItemGroup>
	
```
**Android**
```xml
<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**
```xml
<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](https://www.nuget.org/packages/GoogleCast) 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](https://github.com/MarLoe) created a [Pull-Request](https://github.com/novotnyllc/Zeroconf/pull/255) 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](https://github.com/MarLoe/Zeroconf/tree/ios16/Zeroconf) 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**

```xml
<TargetFrameworks>net6.0;netstandard2.0;net48;xamarinios10</TargetFrameworks>
```

**To**

```xml
<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](https://www.nuget.org/packages/GoogleCast) NuGet package, won't work. So, we need to also clone the latest main version of the [repository](https://github.com/kakone/GoogleCast) 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](https://twitter.com/ivictorhugo)