After Creating Package in Xamarin UWP, Video is Playing Only With Voice, I am Not able to see Video

社会主义新天地 提交于 2019-12-11 04:03:57

问题


I am using MediaManager Plugin with latest version to play a video. everything works fine when i run application in debug mode, but when i create a package for window, video is not showing only voice is heard.

I am using below Package

Plugin.MediaManager.Forms

This is My XAML page

<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);

No Errors Found in package error log, as i mentioned everything works fine when it is debug mode, but not working in release mode


回答1:


Basically there is no way to initialize renderer for video in native code for xamrin.UWP, so we need to manually load render assembly in initialize it in App.xaml.cs of UWP platform

Below is my code where i have load assembly files inside OnLaunched() and replace existing 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();
        }

for more details, here is the link. where you can find more explaination.

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




回答2:


Most likely from the behavior you are describing (and looking at your code), it sounds like it's because the Video is not being run on the UI thread, and this causes the app to play the audio but not the video. So change it to the following:

Device.BeginInvokeOnMainThread(() => { CrossMediaManager.Current.Play(fileName); });


来源:https://stackoverflow.com/questions/56829387/after-creating-package-in-xamarin-uwp-video-is-playing-only-with-voice-i-am-no

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!