You could try to check these,make sure you have stored a media file in the platform project.
On Android, media files must be stored in a subfolder of Resources named raw. The raw folder cannot contain subfolders. The media file must have a Build Action
of AndroidResource
.
then in your page.xaml (don't use layout to wrap MediaElement
):
<?xml version="1.0" encoding="UTF-8"?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="MediaElementDemos.PlayAppPackageVideoResourcePage"
Title="Play app package video resource">
<MediaElement Source="ms-appx:///XamarinForms101UsingEmbeddedImages.mp4"
ShowsPlaybackControls="True" IsLooping="True" AutoPlay="True" />
</ContentPage>
add Device.SetFlags(new string[] { "MediaElement_Experimental" });
in your App.xaml.cs
public App()
{
Device.SetFlags(new string[] { "MediaElement_Experimental" });
InitializeComponent();
MainPage = new NavigationPage(new PlayPage());
}
Update:
If you want to play the mp4 from an URL.
<?xml version="1.0" encoding="UTF-8"?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="MediaElementDemos.PlayAppPackageVideoResourcePage"
Title="Play app package video resource">
<MediaElement Source="https://sec.ch9.ms/ch9/5d93/a1eab4bf-3288-4faf-81c4-294402a85d93/XamarinShow_mid.mp4"
ShowsPlaybackControls="True" IsLooping="True" AutoPlay="True" />
</ContentPage>