I've got this annoying problem which I can't track down where it goes wrong. I'm creating a Windows Media Player in code and I'm trying to loop a video... It loops, but only once...
So it plays the video, and once more. And then it just stop and shows the end of the video. So it seems as if it loops only once.
This is the code I have:
try {
wmPlayer = new AxWMPLib.AxWindowsMediaPlayer();
wmPlayer.enableContextMenu = false;
((System.ComponentModel.ISupportInitialize)(wmPlayer)).BeginInit();
wmPlayer.Name = "wmPlayer";
wmPlayer.Enabled = true;
wmPlayer.Dock = System.Windows.Forms.DockStyle.Fill;
mainForm.Controls.Add(wmPlayer);
((System.ComponentModel.ISupportInitialize)(wmPlayer)).EndInit();
wmPlayer.uiMode = "none";
if(kind == "idle") {
IdleVideo(name);
}
}
catch { }
}
private static void IdleVideo(string name) {
System.Diagnostics.Debug.WriteLine("Video called once");
wmPlayer.URL = @"C:\ProjectSilver\assets\RadarDetectie\idle\" + name + "_idlescreen_movie.ogv";
Debug.WriteLine(wmPlayer.URL);
wmPlayer.settings.setMode("loop", true);
wmPlayer.Ctlcontrols.play();
}
So I hope you guys can help, why doesn't it keep playing?
just use
private void Form1_Load(object sender, EventArgs e)
{
// give the path of your video here
axWindowsMediaPlayer1.URL = "Path of your video";
// this line will automatically start your video
axWindowsMediaPlayer1.settings.autoStart = true;
//here the system will automatially create a thread and will keep on
running your video...
axWindowsMediaPlayer1.settings.setMode("loop", true);
}
Add an event handler for the PlayStateChange
event:
wmPlayer.PlayStateChange += wmPlayer_PlayStateChange;
Then in the event handler check if e.newState==8
which means media ended
:
AxWMPLib.AxWindowsMediaPlayer wmPlayer;
private void player_PlayStateChange(object sender, AxWMPLib._WMPOCXEvents_PlayStateChangeEvent e)
{
if(e.newState==8) // MediaEnded
// call function to play the video again
}
For play states, check this: http://msdn.microsoft.com/en-us/library/windows/desktop/dd562460%28v=vs.85%29.aspx
Edit:
I don't know what you do with kind
, or where the first part of your code is defined, but this worked for me:
AxWMPLib.AxWindowsMediaPlayer wmPlayer;
private void button2_Click(object sender, EventArgs e)
{
wmPlayer = new AxWMPLib.AxWindowsMediaPlayer();
wmPlayer.CreateControl();
wmPlayer.enableContextMenu = false;
((System.ComponentModel.ISupportInitialize)(wmPlayer)).BeginInit();
wmPlayer.Name = "wmPlayer";
wmPlayer.Enabled = true;
wmPlayer.Dock = System.Windows.Forms.DockStyle.Fill;
this.Controls.Add(wmPlayer);
((System.ComponentModel.ISupportInitialize)(wmPlayer)).EndInit();
wmPlayer.uiMode = "none";
wmPlayer.URL = @"C:\...";
wmPlayer.settings.setMode("loop", true);
wmPlayer.Ctlcontrols.play();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With