Xamarin.Forms将视频设置为初始屏幕 [英] Xamarin.Forms Set video as splash screen

查看:322
本文介绍了Xamarin.Forms将视频设置为初始屏幕的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从事xamarin.forms共享项目.我在将视频设置为初始屏幕时遇到问题.我从此处获得了参考.

I am working on xamarin.forms shared project. I am facing problem in setting video as splash screen. I got reference from here.

我面临的问题是视频播放器已初始化并进行了处理,在此期间,AppDelegate代码首先返回.因此不会显示视频,但会发出声音.我有什么想念的吗?

The problem I face is video player is initialized and doing its process and in that time, AppDelegate code returns first. so video is not displayed but its sound is coming. Is there anything I am missing ?

在这里,我合并了示例的VideoControllerVideoViewController.我只使用VideoViewController并从SetMoviePlayer()函数

Here I merged VideoController and VideoViewController of the sample. I only use VideoViewController and refer my video from Resources folder in SetMoviePlayer() function

我尝试的代码:

AppDelegate.cs

[Register("AppDelegate")]
public partial class AppDelegate : Xamarin.Forms.Platform.iOS.FormsApplicationDelegate
{
    public override UIWindow Window { get; set; }
    VideoViewController control = new VideoViewController();

    public override bool FinishedLaunching(UIApplication app, NSDictionary options)
        {
            try
            {
                Window = new UIWindow(UIScreen.MainScreen.Bounds);

                Window.RootViewController = control;

                //global::Xamarin.Forms.Forms.Init();
                //LoadApplication(new App());

                //control.VideoCompletionEvent += Control_VideoCompletionEvent;   // Tried to invoke this on video completion but doesn't help. AppDelegate returns value first then this event is invoked.
                Task.Delay(7000).Wait();   // video is 7 seconds long                
            }
            catch (Exception ex)
            {
                Console.WriteLine("======== "+ex.Message);
            }
            Window.RootViewController = null;
            global::Xamarin.Forms.Forms.Init();
            LoadApplication(new App());
            return true;
        }
        //private bool Control_VideoCompletionEvent()
        //{
        //    //Window.RootViewController = null;
        //    //global::Xamarin.Forms.Forms.Init();
        //    //LoadApplication(new App());
        //    //return true;
        //}
}

VideoViewControllerVideoCutter文件与上面的链接相同.

VideoViewController and VideoCutter Files are same as in the link above.

谢谢

推荐答案

您可以通过以下方式在AppDelegate中启动UIViewControl,并使用MessagingCenter通知在Xamarin.forms中启动Page:

You can launch the UIViewControl in AppDelegate in following way, and use a MessagingCenter to notify launching the Page in Xamarin.forms:

public override bool FinishedLaunching(UIApplication app, NSDictionary options)
{
    global::Xamarin.Forms.Forms.Init();

    Window = new UIWindow(UIScreen.MainScreen.Bounds);

    UIViewController1 control = new UIViewController1();

    Window.RootViewController = control;
    Window.MakeKeyAndVisible();

    MessagingCenter.Subscribe<object, object>(this, "ShowMainScreen", (sender, args) =>
    {
        LoadApplication(new App());
        base.FinishedLaunching(app, options);
    });

    return true;
}

在视频播放完毕后,在VideoViewController中发送MessagingCenter:

And in your VideoViewController, send the MessagingCenter when you video is finished:

  public override void ViewDidLoad()
        {
            View = new UniversalView();

            base.ViewDidLoad();

            // Perform any additional setup after loading the view


            NSTimer.CreateScheduledTimer(7, true, (obj) =>
            {
                MessagingCenter.Send<object, object>(this, "ShowMainScreen", null);
            });
        }

您可以将send操作放入videoCompleteEvent.

You can put the send action in the videoCompleteEvent.

我在这里上传了一个示例,您可以检查它: LaunchViewController-xamarin.forms

Here I uploaded a sample and you can check it: LaunchViewController-xamarin.forms

这篇关于Xamarin.Forms将视频设置为初始屏幕的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆