Levesque Xylia
Levesque Xylia

Reputation: 369

Xamarin Forms 5.0 MediaElement was not found

I have a project in xamarin forms 4.6 that updated to xamarin forms 5.0, but when I run the project. This error occurs.

The type 'xct:MediaElement' was not found. Verify that you are not missing an assembly reference and that all referenced assemblies have been built.

I already added this reference xmlns:xct="http://xamarin.com/schemas/2020/toolkit" in my ContentPage but the problem still exist.

here is my code.

<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
                         xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
                         xmlns:xct="http://xamarin.com/schemas/2020/toolkit"
                         x:Class="Proyekto4Juan.Views.IndexPage">
                <Grid>
            
            
                    <xct:MediaElement x:Name="BgVideo" Source="ms-appx:///video.mp4" ShowsPlaybackControls="False"
                                  IsLooping="True" AutoPlay="True" Aspect="AspectFill"
                                  HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" />
                </Grid
</ContentPage>

Thanks in Advance.

Upvotes: 0

Views: 2202

Answers (1)

Jessie Zhang -MSFT
Jessie Zhang -MSFT

Reputation: 13803

You can recheck if you have installed nuget Xamarin.CommunityToolkit.

And add the following code :

xmlns:xct="clr-namespace:Xamarin.CommunityToolkit.UI.Views;assembly=Xamarin.CommunityToolkit"

The Xamarin Community Toolkit is a collection of common elements for mobile development with Xamarin.Forms that people tend to replicate across multiple apps. It simplifies and demonstrates common developer tasks when building apps with Xamarin.Forms.

For more details, you can check document :Xamarin Community Toolkit MediaElement.

You can also refer to the sample code MediaElementDemos.

A usage sample from above sample is AspectVideoPage.xaml:

<?xml version="1.0" encoding="UTF-8"?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:xct="clr-namespace:Xamarin.CommunityToolkit.UI.Views;assembly=Xamarin.CommunityToolkit"
             xmlns:controls="clr-namespace:MediaElementDemos.Controls"
             x:Class="MediaElementDemos.AspectVideoPage"
             Title="Change aspect ratio">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="*" />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>
        <xct:MediaElement x:Name="mediaElement"
                          Grid.Row="0"
                          AutoPlay="False"
                          ShowsPlaybackControls="True"
                          Source="{StaticResource AdvancedAsync}" />
        <StackLayout Grid.Row="1"
                     Margin="0,0,0,40"
                     Orientation="Horizontal"
                     HorizontalOptions="Center">
            <Label Text="Aspect:"
                   VerticalTextAlignment="Center" />
            <controls:EnumPicker x:Name="aspectEnumPicker"
                                 EnumType="{x:Type Aspect}"
                                 SelectedIndex="0"
                                 SelectedIndexChanged="OnAspectSelectedIndexChanged" />
        </StackLayout>
    </Grid>
</ContentPage>

Upvotes: 2

Related Questions