Search code examples
c#androidxamarinxamarin.formsxamarin.android

Unable to reference native Android view in Xamarin xaml


I'm using baseflow's MediaManager plugin:

https://github.com/Baseflow/XamarinMediaManager

I need to have multiple video views. From reading the documentation, I know I need to create a video view using native android views in my xaml like this:

<mediamanager.platforms.android.video.VideoView
    android:id="@+id/your_videoview"
    android:layout_width="match_parent"
    android:layout_height="300dp" />

I used the following documentation to try and add native view support: https://learn.microsoft.com/en-gb/xamarin/xamarin-forms/platform/native-views/xaml

The problem I'm having is that I can't seem to correctly reference 'android:'. I've added the references and I've set [XamlCompilation(XamlCompilationOptions.Skip)] but still I get the squiggly green lines. I've also cleaned/rebuilt/deleted bin/obj files.

enter image description here

enter image description here

Maybe I'm missing something obvious, maybe there is a code wizard out there that can point me in the right direction.


Solution

  • You don’t need to use any of that! You should try the brand new ‘MediaElement’ control on Xamarin forms. It makes adding videos a piece of cake:

    <MediaElement Source="https://sec.ch9.ms/ch9/5d93/a1eab4bf-3288-4faf-81c4-294402a85d93/XamarinShow_mid.mp4"
              ShowsPlaybackControls="True" />
    

    Even though it’s in preview, it works really smoothly, I watched it in a Kym Philpotts live demo during MS Build 2020. Check out the official docs for it over here: https://learn.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/mediaelement

    Here’s a video to the recorded stream too: https://youtube.com/watch?v=dMR6uaFz0Eg