Let’s assume we have an endless list of mp3’s. At a given point each mp3 fades out (different for each mp3), and the next mp3 starts. So for a short period of time there are the new mp3 and the fading out mp3 together. As it will be streamed away to an icecast server, this must happen inside a buffer.
Right now in a first try I just take two songs from my disk, but the plan is to load songs from everywhere.
I am so stuck, may be someone can help. Tnx in advance!
static byte[] buff = new byte[64];
static int read;
static void Main(string[] args)
{
icecast.Open();
// to make things easier, first just take two songs out of a List
Song actualSong = songs2play[0];
Song nextSong = songs2play[1];
BinaryReader actualSongReader = new BinaryReader(File.Open(actualSong.Path, FileMode.Open));
BinaryReader nextSongReader = new BinaryReader(File.Open(nextSong.Path, FileMode.Open));
DateTime start = DateTime.Now;
while (true)
{
TimeSpan howLong = DateTime.Now - start;
// if the next song starts
if (howLong.Milliseconds > (actualSong.Length - actualSong.FadeoutStart) && (howLong.Milliseconds < (actualSong.Length - actualSong.FadeoutStart + actualSong.FadeoutLength)))
{
read = (actualSongReader.Read(buff, 0, buff.Length)) + nextSongReader.Read(buff, 0, buff.Length);
}
// the first song faded away, play only the new song
else if (howLong.Milliseconds > (actualSong.Length))
{
read = nextSongReader.Read(buff, 0, buff.Length);
}
// only the first song, thew fade out point was not reached yet
else
{
read = actualSongReader.Read(buff, 0, buff.Length);
}
// send buffer to icecast
if (read > 0)
{
icecast.Send(buff, read);
}
else
break;
}
public class Song
{
public string Title;
public string Artist;
public int Length;
public int FadeoutStart;
public int FadeoutLength;
public string Path;
}
Thore Laufenberg is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.