• 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

    • It wasn't "Germany" trying to move away from Windows, it was one state in Germany https://www.neowin.net/news/ge...t-to-linux-and-libreoffice/ I also don't think they "crawled back to Windows". The same state also ditched Teams https://it.slashdot.org/story/...hits-uninstall-on-microsoft
    • Hey folks, I've recently noticed my iPhone (13 Pro) getting insanely hot while playing certain games — especially ones with high graphics like COD Mobile or even during long FaceTime calls. Battery drops fast, the back heats up, and the phone starts lagging a bit too. It honestly reminds me of that GTA San Andreas mission where CJ runs through a burning building with the fire extinguisher — except I don’t have one for my phone 😂 Jokes aside, I’ve: Turned off background app refresh Reduced brightness Closed unnecessary apps Updated to the latest iOS But the issue still pops up during intense tasks. 👉 Anyone else facing this? 👉 Is this normal with newer iPhones or something I should worry about long term? 👉 Could using a MagSafe charger regularly have anything to do with it? Would love to hear your experience or if you’ve got tips to cool things down (besides playing San Andreas. on low graphics haha). Cheers! 
    • It's funny how easy he is to emulate because of such a limited verbal vocabulary.
    • No, moderators and staff can not be blocked for obvious reasons. Individuals with bad intent could block moderators from doing their jobs. We have lots of spam/ users who sign up with bad intent and we are constantly cleaning the board of these troublemakers. The ability to block us would severely hamper us from doing our job. If any member has an issue with a staff member or moderator, you may PM a Supervisor, Steven P. or me to look into the matter.  Best, Barney
    • Would you be open to allowing users to ignore/block staff/moderators here? When trying to do so now, you cannot add a mod/global mod to your ignore/block list. Curious why this is setup this way, is there any way around this?
  • Recent Achievements

    • Conversation Starter
      Jamie Smith earned a badge
      Conversation Starter
    • First Post
      NeoToad777 earned a badge
      First Post
    • Week One Done
      JoeV earned a badge
      Week One Done
    • One Month Later
      VAT Services in UAE earned a badge
      One Month Later
    • First Post
      LsDmT earned a badge
      First Post
  • Popular Contributors

    1. 1
      +primortal
      575
    2. 2
      ATLien_0
      253
    3. 3
      +Edouard
      161
    4. 4
      +FloatingFatMan
      152
    5. 5
      Michael Scrip
      114
  • Tell a friend

    Love Neowin? Tell a friend!