• 0

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
https://www.neowin.net/forum/topic/1065850-net-wmp-end-of-file/
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

  • 0
  On 25/03/2012 at 23:57, Dr_Asik said:

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.

  • 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.

  • 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

This topic is now closed to further replies.
  • Posts

    • Hey Nick! 👋 No worries at all — you're not alone in this, and it's great you're asking for help. Let me walk you through a simple, step-by-step fix using the tool mentioned on that AOMEI Partition Assistant guide — it really does the trick for many people with this exact issue! ✅ Here’s how to restore your USB back to full 256GB on Windows 11: Download & Install AOMEI Partition Assistant Go to the link you shared: AOMEI Partition Assistant and click the Download Freeware button. Insert your USB stick (Sandisk Ultra 256GB) Make sure it's properly connected. Wait for the system to detect it. Launch AOMEI Partition Assistant Once open, you'll see all your connected drives listed. Locate your USB Drive Look for the one that says something like Disk X – Removable and shows only 3.1GB or so. Right-click on your USB Drive’s Partition Then select Delete Partition → confirm the deletion. Now, right-click on the unallocated space (it should now show full unallocated capacity) Choose Create Partition → format it as FAT32 or exFAT (recommended for larger drives) → click OK. Click “Apply” in the top left corner Then hit Proceed to execute the pending operations. Wait a bit... and boom! 🎉 Your USB should now be restored to its full 256GB capacity!
    • When Facebook bought Beat Saber, they promised exactly this would never happen. Facebook can’t not lie.
    • Depends on what you mean by "this data". Nvidia can show you quite a few of those as well in their performance overlay, and I guess they might've assumed that if anyone wants to see more, they'll just use Afterburner as the de facto standard. As for real framerate vs framegen framerate, I don't think they exactly want you to know, given that their marketing has been strongly focused on hiding the real framerate and pretending the generated one is all that matters...
    • Yeah, but that never works out well. You can just give your power user more options and they'll be happy. Your new generation can just go with whatever you think is the best default.
  • Recent Achievements

    • First Post
      Fuzz_c earned a badge
      First Post
    • First Post
      TIGOSS earned a badge
      First Post
    • Week One Done
      slackerzz earned a badge
      Week One Done
    • Week One Done
      vivetool earned a badge
      Week One Done
    • Reacting Well
      pnajbar earned a badge
      Reacting Well
  • Popular Contributors

    1. 1
      +primortal
      710
    2. 2
      ATLien_0
      279
    3. 3
      Michael Scrip
      209
    4. 4
      +FloatingFatMan
      200
    5. 5
      Steven P.
      131
  • Tell a friend

    Love Neowin? Tell a friend!