How can I use the Android Exoplayer to play videos?

Kim Strasser 816 Reputation points
2024-07-17T12:28:29.27+00:00

Currently I use the Xamarin MediaManager to play videos: https://github.com/Baseflow/XamarinMediaManager

Is it possible to use the Android Exoplayer instead to play videos? I want to find out if the black screen that appears before a video is played will be the same when I use Android Exoplayer:

https://learn.microsoft.com/en-us/answers/questions/1820407/the-display-of-my-android-device-gets-black-for-a

How can I use the Android Exoplayer to play videos instead of the Xamarin MediaManager?

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);
        }
    }
}

.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
3,198 questions
{count} votes