您可以尝试检查这些,确保您已在平台项目中存储了媒体文件。
在 Android 上,媒体文件必须存储在名为raw的Resources子文件夹中。原始文件夹不能包含子文件夹。媒体文件必须具有.Build Action
AndroidResource

然后在您的 page.xaml 中(不要使用布局来换行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>
添加Device.SetFlags(new string[] { "MediaElement_Experimental" });
您的App.xaml.cs
public App()
{
Device.SetFlags(new string[] { "MediaElement_Experimental" });
InitializeComponent();
MainPage = new NavigationPage(new PlayPage());
}
更新:
如果您想从 URL 播放 mp4。
<?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>