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

标签 xamarin.forms xamarin.ios avplayer splash-screen

我正在处理 xamarin.forms共享项目。我在将视频设置为启动画面时遇到问题。我从 here 得到了引用.

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

我在这里合并 VideoControllerVideoViewController的样本。我只用 VideoViewController并从 SetMoviePlayer() 中的 Resources 文件夹中引用我的视频功能

我试过的代码:

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文件与上面链接中的相同。

谢谢

最佳答案

您可以通过以下方式在 AppDelegate 中启动 UIViewControl,并使用 MessagingCenter通知在 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;
}
而在您的 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);
    });
}
您可以将发送操作放在 videoCompleteEvent 中.
这里我上传了一个样本,你可以查看:LaunchViewController-xamarin.forms

关于Xamarin.Forms 将视频设置为启动画面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56649595/

相关文章:

xamarin.ios - 单点触控 : Example of an implementation of a finite length task executing when exiting iOS application?

c# - 如何使用 Xamarin.iOS (C#) 以编程方式截取 iPhone/iPad 的屏幕截图?

c# - 自动生成的 XAML.g.cs 文件在 Xamarin Forms PCL 项目中不可编译

xamarin.forms - 如何只有在有键盘的情况下才移动滚动条

xamarin - 如果未在使用模板的 XAML 中指定,我怎样才能使模板内的 HeightRequest 被忽略?

ios - 对自定义 AVPlayer 的错误引用

ios - AVPlayer - 全屏切换

c# - 我可以隐藏 Xamarin.Auth NavigationBar 吗?

c# - MonoDevelop iPhone 模拟器在调试运行时加载退出,问题似乎与一个内容文件有关

objective-c - 如何停止 AVPlayer 中的视频?