-
Notifications
You must be signed in to change notification settings - Fork 23
Description
I'm reaching this problem now to ask for help from whom is knowledgeable for setting up command to initialize video on the screen. Whenever I used to do that in my own way of coding which I don't know if is this was really the proper to play video on the screen but since it did not popped the visibility of the video but was successful to initialize its sounds. I'm reaching up for everyone's kindness 🙏😇 please help me. Here's my own tailored code below (by the way, I'm just still an experienced user of C# and I'm not really so knowledgeable yet);
using System;
using Android.App;
using Android.Graphics.Drawables;
using Android.Views;
using Android.Widget;
using NativeUiLib;
using System.Linq;
using System.IO;
using Android.Graphics;
using Android.Media;
using Android.OS;
using Android.Content;
using Android;
namespace introScreenView
{
public static class Program
{
private static MediaPlayer mediaPlayer;
public static void PlayVideo(string filePath)
{
try
{
var VideoPath = Android.OS.Environment.GetExternalStoragePublicDirectory(Android.OS.Environment.DirectoryDownloads).AbsolutePath + "/bgVideo.mp4";
if (File.Exists(VideoPath))
{
mediaPlayer = MediaPlayer.Create(Android.App.Application.Context, Android.Net.Uri.Parse(VideoPath));
if (mediaPlayer != null)
{
mediaPlayer.Start();
}
else
{
Console.WriteLine("Media player is null.");
}
}
else
{
Console.WriteLine("File not found: " + VideoPath);
}
}
catch (Exception ex)
{
Console.WriteLine("An error occurred: " + ex.Message);
}
}
public static void StopVideo()
{
try
{
if (mediaPlayer != null)
{
mediaPlayer.Stop();
mediaPlayer.Release();
mediaPlayer = null;
}
}
catch (Exception ex)
{
Console.WriteLine("An error occurred: " + ex.Message);
}
}
public static void PauseVideo()
{
try
{
if (mediaPlayer != null)
{
mediaPlayer.Pause();
}
}
catch (Exception ex)
{
Console.WriteLine("An error occurred: " + ex.Message);
}
}
public static void ResumeVideo()
{
try
{
if (mediaPlayer != null)
{
mediaPlayer.Start();
}
}
catch (Exception ex)
{
Console.WriteLine("An error occurred: " + ex.Message);
}
}
public static void Main()
{
var layout = new NativeUiLib.LinearLayout();
PlayVideo("bgVideo.mp4");
//program logics
var skipViewButton = new NativeUiLib.Button();
skipViewButton.Text = "Skip";
skipViewButton.Click += (sender, e) =>
{
StopVideo();
};
layout.AddView(skipViewButton);
layout.Show();
}
}
}