2

我正在使用最新版本的 MediaManager 插件来播放视频。当我在调试模式下运行应用程序时一切正常,但是当我为窗口创建一个包时,视频没有显示,只听到声音。

我正在使用以下包

Plugin.MediaManager.Forms

这是我的 XAML 页面

<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="Digi_Sign.Views.MediaScreen"
             xmlns:forms="clr-namespace:MediaManager.Forms;assembly=MediaManager.Forms"
             BackgroundColor="Black">
    <ContentPage.Content>
        <Grid x:Name="stkLayout" VerticalOptions="CenterAndExpand" HorizontalOptions="CenterAndExpand" BackgroundColor="Black">
            <forms:VideoView VideoAspect="AspectFill"  x:Name="videoPlayer" ShowControls="False"  />
             </Grid>
    </ContentPage.Content>
</ContentPage>

客户服务页面

CrossMediaManager.Current.Play(fileName);

在包错误日志中未发现错误,正如我提到的,在调试模式下一切正常,但在发布模式下不工作

4

2 回答 2

2

xamrin.UWP的本机代码基本上没有办法初始化视频渲染器,所以我们需要在UWP平台的App.xaml.cs中手动加载渲染程序集进行初始化

下面是我在OnLaunched()中加载程序集文件并替换现有Xamarin.Forms.Forms.Init()的代码

  protected override void OnLaunched(LaunchActivatedEventArgs e)
        {
            Windows.UI.Xaml.Controls.Frame rootFrame = Window.Current.Content as Windows.UI.Xaml.Controls.Frame;
            if (rootFrame == null)
            {

                rootFrame = new Windows.UI.Xaml.Controls.Frame();
                rootFrame.NavigationFailed += OnNavigationFailed;

                List<Assembly> assembliesToAdd = new List<Assembly>();
                assembliesToAdd.Add(typeof(VideoViewRenderer).GetTypeInfo().Assembly);
                Xamarin.Forms.Forms.Init(e, assembliesToAdd);


                // Place the frame in the current Window
                Window.Current.Content = rootFrame;
            }

            if (rootFrame.Content == null)
            {
                rootFrame.Navigate(typeof(MainPage), e.Arguments);
            }

            Window.Current.Activate();
        }

有关更多详细信息,这里是链接。在哪里可以找到更多解释。

https://forums.xamarin.com/discussion/119451/crossmedia-works-in-debug-but-not-in-release-for-uwp-error-msg-about-onecore

于 2019-07-04T18:35:00.147 回答
0

很可能从您描述的行为(并查看您的代码)来看,这听起来像是因为视频没有在 UI 线程上运行,这导致应用程序播放音频而不是视频。因此将其更改为以下内容:

Device.BeginInvokeOnMainThread(() => { CrossMediaManager.Current.Play(fileName); });
于 2019-07-02T21:29:15.020 回答