适用于Android的新Xamarin Forms 4.6 MediaElement mot

问题描述 投票:4回答:1

我在一个非常简单的Xamarin Forms Shell项目中试用了新的Xamarin Forms 4.6.0.726 MediaElement控件。我在ContentPage中添加了MediaElement控件,并设置了其属性(true时为AutoPlay,true时为IsLooping,mp4文件的Source,true的ShowPlaybackControls)。我还在App.xaml.cs中为MediaElement添加了实验标志。

[当我运行该应用程序时,在iOS上播放视频,同时显示声音,图像和播放器控件,但在Android上不起作用。在Android上,播放器控件未显示,没有任何反应。

其他人有这个问题吗?

android xamarin.forms mediaelement xamarin-forms-4
1个回答
0
投票

您可以尝试检查这些,确保已在平台项目中存储了媒体文件。

在Android上,媒体文件必须存储在名为raw资源的子文件夹中。 raw文件夹不能包含子文件夹。媒体文件的Build Action必须为AndroidResource

enter image description here

然后在您的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>
© www.soinside.com 2019 - 2024. All rights reserved.