Unable to reference native Android view in Xamarin xaml

Viewed 264

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://docs.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.

2 Answers

You can use native views in Forms. Unfortunately, this here is not the case. Your native view needs its own *.axml file in the Android project in order for you to use it.

Looking at the rest of the code that you need for this particular configuration, it should also be written natively (in the Android project) - FindViewById && SetView are all code that needs to be in the Android project.

Unfortunately, in some cases not everything has been prepared for usage in the shared project and occasionally you need to get "your hands dirty" and go "native" in order to configure your code the way you wish.

What you should do it use it as it is being shown in Xamarin.Forms section. Then, you can apply the modifications that are documented in Add Video Player to the UI. You can create a class that inherits from VideoViewRenderer and modify your view there. If you are not familiar with customs renderers, you can read more about them here.

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://docs.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

Related