Last active
May 28, 2021 18:05
-
-
Save osbornm/4431513 to your computer and use it in GitHub Desktop.
NAudio Playlist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
^