views:

484

answers:

2

Hi all

I have an mp3 player that sends MCI commands to play pause/ff/rw/stop the audio files etc and the only thing i can't figure out how to do is send an MCI command to tell it to play the next song when the current one's finished playing.

The songs are in a ListBox. I have no problems actually selecting the next song, I just need to find out when to play the next song on the playlist. I'd appreciate any help at all

Thank you :)

+2  A: 

Can you check the duration of the mp3 and maintain a timer along side the mp3 playing? Pause the timer when the mp3 is paused, etc. When the duration of the song has played, play the next song.

scottm
Unfortunately I have no idea how to check the duration of the track. Can this be done using MCI? I have referenced the docs for MCI, but they seem rather limited.
lucifer
Just googled and found this class that will give you the length in seconds: http://devhood.com/tutorials/tutorial_details.aspx?tutorial_id=79
scottm
Perfect! Thanks Scottm :D
lucifer
+3  A: 

Sorry to dredge this up after a month or so, but I think I may have a nicer answer...

You can do the length in seconds thing, or you can have MCI notify you itself.

When you send your "play" command, tack on "notify" after the media's alias, and then pass your window's handle (I'm using System.Windows.Forms, hence the 'this.Handle'), like so:

uint playOk = mciSendString("play MediaFile notify", null, 0, this.Handle);

That tells MCI to send you a notification when the command completes or is interrupted. Then you can just filter the messages your window receives to see if anything you're interested comes through:

private const int MM_MCINOTIFY = 0x03b9;
private const int MCI_NOTIFY_SUCCESS = 0x01;    
private const int MCI_NOTIFY_SUPERSEDED = 0x02;
private const int MCI_NOTIFY_ABORTED = 0x04;
private const int MCI_NOTIFY_FAILURE = 0x08;

protected override void WndProc(ref Message m)
{
  if (m.Msg == MM_MCINOTIFY)
  {
    switch (m.WParam.ToInt32())
    {
      case MCI_NOTIFY_SUCCESS:
        // success handling
        break;
      case MCI_NOTIFY_SUPERSEDED:
        // superseded handling
        break;
      case MCI_NOTIFY_ABORTED:
        // abort handling
        break;
      case MCI_NOTIFY_FAILURE:
        // failure! handling
        break;
      default:
        // haha
        break;
    }
  }
  base.WndProc(ref m);
}

This seems to be working just fine for me. I hope this helps. ;)

Guy
Thanks heaps Guy! This is much appreciated, I've been looking for a solution for ages. :D
lucifer