Hello,
How can I hide this bar in my game when a video is playing?
Firstly, you add Activity's Window to the Game1.s constructor. When you execute the ShowTheVideo
method, you can hide the bar by windowInsetsController.Hide(WindowInsetsCompat.Type.NavigationBars()); windowInsetsController.SystemBarsBehavior = WindowInsetsControllerCompat.BehaviorShowTransientBarsBySwipe;
You can refer to the following code, If the video is finished, this bar will show again. If you want to full screen, please move code about showing system bars in the MediaItemFinished
event.
public class Game1 : Game
{
private GraphicsDeviceManager _graphics;
private SpriteBatch _spriteBatch;
private Activity1 activity1;
private Window window;
public Game1(Activity1 activity1, Window window)
{
this.window = window;
this.activity1 = activity1;
_graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
}
public async void ShowTheVideo()
{
VideoDialog customDialog = new VideoDialog(activity1);
customDialog.SetCancelable(false);
customDialog.Show();
await CrossMediaManager.Current.Play("https://sec.ch9.ms/ch9/5d93/a1eab4bf-3288-4faf-81c4-294402a85d93/XamarinShow_mid.mp4");
// Hide system bars
WindowCompat.SetDecorFitsSystemWindows(window, false);
WindowInsetsControllerCompat windowInsetsController = new WindowInsetsControllerCompat(window, window.DecorView);
windowInsetsController.Hide(WindowInsetsCompat.Type.NavigationBars());
windowInsetsController.SystemBarsBehavior = WindowInsetsControllerCompat.BehaviorShowTransientBarsBySwipe;
CrossMediaManager.Current.MediaItemFinished += (s, e) =>
{
customDialog.Cancel();
// show system bars
WindowCompat.SetDecorFitsSystemWindows(window, true);
WindowInsetsControllerCompat windowInsetsController = new WindowInsetsControllerCompat(window, window.DecorView);
windowInsetsController.Show(WindowInsetsCompat.Type.NavigationBars());
};
}
In the end, if you init the Game1. Please add this.Window in _game = new Game1(this,this.Window);
line.
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
CrossMediaManager.Current.Init(this);
_game = new Game1(this,this.Window);
....
}
Best Regards,
Leon Lu
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.