The display of my Android device gets black for a short time before the video gets displayed

Kim Strasser 1,036 Reputation points
2024-07-16T13:07:13.0066667+00:00

The display of my Android device gets black for a short time before the video gets displayed. I use this code to play a video and I don´t know why the display gets completely black for 1-2 seconds before the video gets played. It´s not bad that the display gets black for a short time but I want to know if it would be possible to avoid the black screen before the video gets displayed.

Why does the display gets black for a short time before the video gets displayed?

Acitivity1.cs:

_game = new Game1(this, this.Window);

Game1.cs:

 private Activity1 activity1;    
 private Android.Views.Window window;     

public async void ShowTheVideo()
   {
       VideoDialog customDialog = new VideoDialog(activity1);
       customDialog.SetCancelable(false);
       customDialog.Show();
       await CrossMediaManager.Current.Play("https://videos.pexels.com/video-files/7356431/7356431-hd_1280_720_25fps.mp4");
     
       CrossMediaManager.Current.MediaItemFinished += (s, e) =>
       {
           customDialog.Cancel();
       };
   }

VideoDialog.cs:

using Android.App;
using Android.Views;
using Android.Content;
using Android.Graphics.Drawables;
using Android.OS;
using AndroidX.Core.View;

namespace MyAndroidProject
{
    public class VideoDialog : Dialog
    {
        public VideoDialog(Context context) : base(context)
        {
        }
        protected override void OnCreate(Bundle? savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
         
            Window.RequestFeature(WindowFeatures.NoTitle);
            WindowCompat.SetDecorFitsSystemWindows(Window, false);
            WindowInsetsControllerCompat windowInsetsController = new WindowInsetsControllerCompat(Window, Window.DecorView);
            windowInsetsController.Hide(WindowInsetsCompat.Type.NavigationBars());
            windowInsetsController.SystemBarsBehavior = WindowInsetsControllerCompat.BehaviorShowTransientBarsBySwipe;
            View view = LayoutInflater.From(Context).Inflate(Resource.Layout.Activity_main, null);
            SetContentView(view);
            Window.SetBackgroundDrawable(new ColorDrawable());
            Window.SetLayout(WindowManagerLayoutParams.MatchParent, WindowManagerLayoutParams.MatchParent);
        }
    }
}

Visual Studio
Visual Studio
A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.
5,144 questions
.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
3,545 questions
{count} votes

Accepted answer
  1. Yonglun Liu (Shanghai Wicresoft Co,.Ltd.) 43,446 Reputation points Microsoft Vendor
    2024-07-17T05:59:37.7+00:00

    Hello,

    Why does the display gets black for a short time before the video gets displayed?

    This is because after the video playback control is loaded, your program needs to read the video file as a file stream and then parse it before it can be displayed on the screen. This process takes up the program's computing resources, so a brief black screen will appear.

    It´s not bad that the display gets black for a short time but I want to know if it would be possible to avoid the black screen before the video gets displayed.

    Since the black screen is caused by loading, and this player is a third-party plug-in, it is recommended that you post this question to the official repository of the plug-in to ask if there is a way to preload to avoid the black screen.

    Best Regards,

    Alec Liu.


    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.

    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.