I am working on xamarin.forms
shared project. I am facing problem in setting video as splash screen. I got reference from here.
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 ?
Here I merged VideoController
and VideoViewController
of the sample. I only use VideoViewController
and refer my video from Resources folder in SetMoviePlayer()
function
The code I tried :
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
and VideoCutter
Files are same as in the link above.
Thank you
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);
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;
}
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, false, (obj) =>
{
MessagingCenter.Send<object, object>(this, "ShowMainScreen", null);
});
}
You can put the send action in the videoCompleteEvent
.
Here I uploaded a sample and you can check it: LaunchViewController-xamarin.forms
In your case, this line is the problem:
LoadApplication(new App());
As it causes Xamarin to replace your VideoViewController
with its own ViewController
. So you need to put it somewhere else after the video is completed (I see that you have some commented out code for that event).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With