如何在C#

时间:2019-04-08 17:53:33

标签: c# naudio

我正在尝试为学校设计一个项目,包括c#和数据库。它基本上是一个音频播放器,它从SQL Server中的路径获取轨道 本地数据库。

我的问题是,由于我自己无法解决问题,我该如何播放歌曲列表?

我正在使用名为WaveOutEventoutputDevice的{​​{1}}对象。

我尝试获取列表的索引并对其进行播放,并且可以“运行”,或者更好,调试表明AudioFileReader中的PlaybackState是“正在播放”,但实际上并没有播放音乐。

以下是一些代码:

它的工作部分:

outputDevice

不起作用的部分:

if (songsQueue.Count != 0)
{
    //where nQueue is the position of the list
    DataGridViewRow row = (DataGridViewRow)songsQueue[nQueue];

    if (outputDevice == null)
    {
        outputDevice = new WaveOutEvent();
        outputDevice.PlaybackStopped += OnPlaybackStopped;
    }

    if (audioReader == null)
    {
        string path = row.Cells[7].Value.ToString();
        audioReader = new AudioFileReader(Application.StartupPath + @path);
        outputDevice.Init(audioReader);
        lblArtist.Text = row.Cells[2].Value.ToString();
        lblTrack.Text = row.Cells[3].Value.ToString();
        outputDevice.Play();
    }
}

我希望它能够播放,因为标签audioReader.Dispose(); outputDevice.Dispose(); DataGridViewRow row = (DataGridViewRow)songsQueue[nQueue + 1]; string path = row.Cells[7].Value.ToString(); audioReader = new AudioFileReader(Application.StartupPath + @path); outputDevice = new WaveOutEvent(); outputDevice.Init(audioReader); lblArtist.Text = row.Cells[2].Value.ToString(); lblTrack.Text = row.Cells[3].Value.ToString(); outputDevice.Play(); lblArtist会发生变化,而lblTrack则表示正在播放。

谢谢大家的帮助! :D

0 个答案:

没有答案