Как воспроизвести список треков с NAudio в C # - PullRequest
1 голос
/ 08 апреля 2019

Я пытаюсь сделать проект для школы, включая c # и базы данных. Это в основном аудиоплеер, который берет дорожки из путей в SQL Server база данных локально.

У меня вопрос, поскольку я не могу решить свою проблему самостоятельно, как я могу воспроизвести список песен?

Я использую WaveOutEvent объект с именем outputDevice и 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 меняются, а outputDevice говорит, что он играет.

Спасибо всем заранее за помощь! : D

...