我正在处理 xamarin.forms
共享项目。我在将视频设置为启动画面时遇到问题。我从 here 得到了引用.
我面临的问题是视频播放器已初始化并执行其过程,此时 AppDelegate 代码首先返回。所以视频没有显示,但它的声音来了。有什么我想念的吗?
我在这里合并 VideoController
和 VideoViewController
的样本。我只用 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;
//}
}
VideoViewController
和 VideoCutter
文件与上面链接中的相同。谢谢
最佳答案
您可以通过以下方式在 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/