I have a simple form that should start an mp4 soundless video in fullscreen, unfortunately I haven't be able to do that. My form consists of an axWindowsMediaPlayer control and a button when clicked video plays in full screen, I just needed that when I start the form the video starts in full screen without need to click the button. Thank you for some hints.
This is my code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using AxWMPLib;
using WMPLib;
using static System.Windows.Forms.VisualStyles.VisualStyleElement.TrackBar;
namespace Ethen
{
public partial class FrmAzkar : Form
{
private int Tiks;
public FrmAzkar()
{
InitializeComponent();
axWindowsMediaPlayer1.uiMode = "none";
TmrAzkar.Start();
}
private void FrmAzkar_Load(object sender, EventArgs e)
{
string path_to_video_file = "C:\\Mawakit-Al-Salat\\azkarFajr.mp4";
if (File.Exists(path_to_video_file))
{
axWindowsMediaPlayer1.URL = path_to_video_file;
axWindowsMediaPlayer1.Ctlcontrols.play();
}
else
{
MessageBox.Show("File not Found");
}
}
private void TmrAzkar_Tick(object sender, EventArgs e)
{
Tiks++;
this.Text = Tiks.ToString();
if (Tiks == 540)
{
this.Text = "Done";
TmrAzkar.Stop();
this.Close();
}
}
private void button1_Click(object sender, EventArgs e)
{
if (axWindowsMediaPlayer1.playState == WMPPlayState.wmppsPlaying)
{
axWindowsMediaPlayer1.fullScreen = true;
}
}
}
}
1 Answer 1
I had to do it from the StatusChange() event of the Media Player control.
Select the Media Player control (axWindowsMediaPlayer1), then switch to the events for it in the properties pane. Find the "StatusChange" event and double click it.
Now switch to fullscreen mode from there:
private void axWindowsMediaPlayer1_StatusChange(object sender, EventArgs e)
{
if (axWindowsMediaPlayer1.playState == WMPLib.WMPPlayState.wmppsPlaying)
{
axWindowsMediaPlayer1.fullScreen = true;
}
}
This worked for me in a bare bones UI with a video URL set in the Load() event of the form.
axWindowsMediaPlayer1.fullScreen = true;code into theShown()event of the Form?Load()event occurs BEFORE the form (and the player) have been displayed. This is why I suggested theShown()event of the form, which occurs AFTER the form has been displayed. This should guarantee that the player control has already been created.