Skip to content

Instantly share code, notes, and snippets.

@osbornm
Last active May 28, 2021 18:05
Show Gist options
  • Save osbornm/4431513 to your computer and use it in GitHub Desktop.
Save osbornm/4431513 to your computer and use it in GitHub Desktop.
NAudio Playlist
namespace ConsoleApplication4
{
class Program
{
static void Main(string[] args)
{
var playlist = new List<string>{ @"c:\development\test\sound.MP3",
@"c:\development\test\sound2.MP3" };
var playr = new playr(playlist);
playr.PlaySong();
Console.WriteLine("Playing your songs..");
Console.ReadLine();
}
public class playr
{
private Queue<string> playlist;
private IWavePlayer player;
private WaveStream fileWaveStream;
public playr(List<string> startingPlaylist)
{
playlist = new Queue<string>(startingPlaylist);
}
public void PlaySong()
{
if (playlist.Count < 1)
{
return;
}
if (player != null && player.PlaybackState != PlaybackState.Stopped)
{
player.Stop();
}
if (fileWaveStream != null)
{
fileWaveStream.Dispose();
}
if (player != null)
{
player.Dispose();
player = null;
}
player = new WaveOutEvent();
fileWaveStream = new AudioFileReader(playlist.Dequeue());
player.Init(fileWaveStream);
player.PlaybackStopped += (sender, evn) => { PlaySong(); };
player.Play();
}
}
}
}
@ONagyGergo
Copy link

^

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment