在 Xamarin UWP 中创建包后,视频仅通过语音播放,我看不到视频

2024-03-25

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

我正在使用下面的包

插件.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>

CS Page

CrossMediaManager.Current.Play(fileName);

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


xamarin.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 https://forums.xamarin.com/discussion/119451/crossmedia-works-in-debug-but-not-in-release-for-uwp-error-msg-about-onecore

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

在 Xamarin UWP 中创建包后,视频仅通过语音播放,我看不到视频 的相关文章

随机推荐