我正在开发一个简单的mp3播放器。我使用WMPLib来播放mp3文件。
我在数据网格视图中显示所有的曲目,在那里双击播放选定的曲目。该程序播放正确的歌曲,但一旦我开始滚动或按按钮相当快,歌曲停止播放。
这是我用来演奏个人曲目的方法:
public static void playTrack(int t)
{
Library l = new Library();
WMPLib.WindowsMediaPlayer song = new WMPLib.WindowsMediaPlayer();
song.URL = l.myLibrary[t].Patch;
song.controls.play();
}当在单独的类中引发dataGridView1_CellContentDoubleClick时,我调用上述方法。
你们知道为什么会这样吗?
我需要使用多线程来修复它吗?
我还认为我的程序的UI太“重”了,因为我在自定义控件中使用多个嵌套面板。我包括我正在运行的应用程序的打印屏幕。

发布于 2016-01-16 15:04:17
好吧,我找到了问题的答案。只需将Library和WMPLib声明为我方法之外的字段,如下所示:
static Library l;
static WMPLib.WindowsMediaPlayer song;
public static void playTrack(int t)
{
l = new Library();
song = new WMPLib.WindowsMediaPlayer();
song.URL = l.myLibrary[t].Patch;
song.controls.play();
}我希望这对某人有帮助:)
https://stackoverflow.com/questions/34828133
复制相似问题