Xamarin.Forms 将视频设置为启动画面

Gay*_*ale 4 splash-screen xamarin.ios avplayer xamarin.forms

我正在研究xamarin.forms共享项目。我在将视频设置为启动画面时遇到问题。我从这里得到了参考。

我面临的问题是视频播放器已初始化并执行其过程,此时 AppDelegate 代码首先返回。所以视频没有显示,但它的声音来了。有什么我想念的吗?

在这里,我合并VideoControllerVideoViewController样品。我只VideoViewControllerSetMoviePlayer()功能中使用和引用来自资源文件夹的视频

我试过的代码:

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;
        //}
}
Run Code Online (Sandbox Code Playgroud)

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

谢谢

Jac*_*Hua 5

您可以通过以下方式在 AppDelegate 中启动 UIViewControl,并使用 aMessagingCenter来通知在 中启动页面Xamarin.forms

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

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

    var control = new VideoViewController();

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

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

    return true;
}
Run Code Online (Sandbox Code Playgroud)

并在您的VideoViewController, 发送MessagingCenter视频完成后:

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

    // Perform any additional setup after loading the view
            
    NSTimer.CreateScheduledTimer(7, false, (obj) =>
    {
        MessagingCenter.Send<object, object>(this, "ShowMainScreen", null);
    });
}
Run Code Online (Sandbox Code Playgroud)

您可以将发送操作放在videoCompleteEvent.

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