歌曲播放完毕了吗? (C#MCI)

发布于 2024-08-25 07:48:22 字数 185 浏览 3 评论 0原文

我有一个 mp3 播放器,它发送 MCI 命令来播放暂停/ff/rw/停止音频文件等,我唯一不知道该怎么做的是发送 MCI 命令告诉它在播放时播放下一首歌曲当前播放完毕。

这些歌曲位于列表框中。我实际上选择下一首歌曲没有问题,我只需要找出何时播放播放列表上的下一首歌曲。如果有任何帮助,我将不胜感激,

谢谢:)

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 :)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

太阳男子 2024-09-01 07:48:22

抱歉在一个月左右的时间后才把这个问题挖出来,但我认为我可能有一个更好的答案...

您可以以秒为单位完成长度,或者您可以让 MCI 自行通知您。

当您发送“播放”命令时,在媒体别名后添加“通知”,然后传递窗口句柄(我使用的是 System.Windows.Forms,因此是“this.Handle”),如下所示

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

: MCI 在命令完成或中断时向您发送通知。然后,您可以过滤窗口收到的消息,看看是否有您感兴趣的消息:

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);
}

这似乎对我来说效果很好。我希望这有帮助。 ;)

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. ;)

芸娘子的小脾气 2024-09-01 07:48:22

你能检查 mp3 的持续时间并在 mp3 播放的同时维护一个计时器吗?当 mp3 暂停等时暂停计时器。当歌曲播放完时,播放下一首歌曲。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文