c# 检测音乐文件何时停止在 WMPLib 中播放

c# Detecting when a music file has stopped playing in the WMPLib

我需要知道音乐文件何时停止播放以播放我制作的播放列表字符串数组中的下一首歌曲。

我使用 WMPLib,这是我播放歌曲的代码:

https://gyazo.com/993d8ea2dff20316f6c98ff88ab57394 + under a button event I use播放文件(@playlist[0]);`

我还意识到我有内存泄漏,所以如果有人恰好也知道为每首歌曲修复该问题的代码,那会很酷。

一种解决方案是立即为 Windows Media Player 提供整个播放列表,这样您就不必担心了。请参阅 How to add multiple files to a playlist. On the other hand, you already subscribed to the PlayStateChange event. https://msdn.microsoft.com/en-us/library/windows/desktop/dd562460%28v=vs.85%29.aspx 描述所有可能的状态,我确信这些 PlayStateChanges 中的一个是适合您的。也许 MediaEnded