• 0

[.NET] WMP End Of File


Question

Hello gang,

I had to switch an app from VLC to WMP (VLC is a great media player, but the 2.0 version affected all the interfaces so...)

I am trying to find the event that gets fired when a local file has completed playing. The EndOfStream does not file for local files (drat) and the PlayStateChange fires twice for "WMPLib.WMPPlayState.wmppsStopped" I could set a local variable, but before I got down that Hack Path I wanted to see if anyone knows of the proper event.

thanks.

Link to comment
Share on other sites

5 answers to this question

Recommended Posts

  • 0

Just took a quick look at the documentation: it seems that when the PlayStateChange event is fired, you need to check the argument passed (which is an integer) to determine what happened. In particular, the value 8 means "MediaEnded", which might be what you need. See http://msdn.microsoft.com/en-us/library/windows/desktop/dd562460(v=vs.85).aspx

Link to comment
Share on other sites

  • 0

Just took a quick look at the documentation: it seems that when the PlayStateChange event is fired, you need to check the argument passed (which is an integer) to determine what happened. In particular, the value 8 means "MediaEnded", which might be what you need. See http://msdn.microsof...0(v=vs.85).aspx

Thanks, but I knew that. This value: "WMPLib.WMPPlayState.wmppsStopped" is number 8. I have a small test bed but when that code runs and calls a "NextMedia" function, that function does not run. I have taken the advice I found elsewhere in that I have a timer (hack!) that is enabled when the media stops (hack!) and that calls the "NextMedia", which works (HACK!)

Very strange.

Link to comment
Share on other sites

  • 0

Strange indeed, I can't reproduce your problem. Here's what I tried:

- Created a new Winforms project

- Added a reference to Windows Media Player (File Version 12.0.7601.17514, there was a second one but older)

- Added the control to the toolbox, dragged it on the form, renamed it to mediaPlayer

- Added a menu to open a file

- Added the following code:

using System;
using System.Diagnostics;
using System.Windows.Forms;
namespace WmpTest {
public partial class Form1 : Form {

public Form1() {
InitializeComponent();
mediaPlayer.PlayStateChange += mediaPlayer_PlayStateChange;
}
void mediaPlayer_PlayStateChange(object sender, AxWMPLib._WMPOCXEvents_PlayStateChangeEvent e) {
if (e.newState == (int)WMPLib.WMPPlayState.wmppsMediaEnded) {
Debug.WriteLine("Got MediaEnded event");
}
}
void ouvrirToolStripMenuItem_Click(object sender, EventArgs e) {
var openFileDialog = new OpenFileDialog();
if (openFileDialog.ShowDialog() == DialogResult.OK) {
mediaPlayer.URL = openFileDialog.FileName;
}
}
}
}[/CODE]

When a file finishes playing, I only see "Got MediaEnded event" once in the Debug output window.

Link to comment
Share on other sites

  • 0

Here's some code that you can use in your PlayStateChange event handler to see what is triggered in what order:

var enumValues = (int[])Enum.GetValues(typeof(WMPLib.WMPPlayState));
var enumNames = Enum.GetNames(typeof(WMPLib.WMPPlayState));
for(int i = 0; i < enumValues.Length; ++i) {
if (e.newState == enumValues[i]) {
Debug.WriteLine(enumNames[i]);
}
}[/CODE]

It'll print the names of all the events in the Output window of Visual Studio during debugging. This is what I see when I set the URL and let it play to completion:

wmppsTransitioning

wmppsTransitioning

wmppsPlaying

wmppsMediaEnded

wmppsTransitioning

wmppsStopped

Link to comment
Share on other sites

This topic is now closed to further replies.