Exemplo n.º 1
0
        private async void EventLoop()
        {
            ShouldRun = true;
            IsStarted = true;
            while (ShouldRun)
            {
                SpinWait.SpinUntil(() => EnsureCurrentSource());

                byte[] buffer = new byte[BufferSize];

                int bytesRead = await CurrentSource.Stream.ReadAsync(buffer, 0, buffer.Length);

                LOGGER.Trace("Bytes read: {0}", bytesRead);

                if (bytesRead == 0)
                {
                    MoveToNextTrack();
                    continue;
                }

                foreach (IRadioClient client in RadioClients.ToList())
                {
                    var streamTask = RadioStreamTo(client, buffer, bytesRead);
                }
            }
            IsStarted = false;
        }
Exemplo n.º 2
0
        private async Task RadioStreamTo(IRadioClient client, byte[] buffer, int count)
        {
            if (client.OutputStream.CanWrite == false)
            {
                client.OutputStream.Dispose();
                RadioClients.Remove(client);
                return;
            }
            try
            {
                await client.OutputStream.WriteAsync(buffer, 0, count);

                await client.OutputStream.FlushAsync();
            }
            catch (Exception e)
            {
                LOGGER.Error(e, "Error while writing to client OutputStream!");
                client.OutputStream.Dispose();
                RadioClients.Remove(client);
            }
        }
Exemplo n.º 3
0
 public void RemoveRadioClient(IRadioClient client)
 {
     RadioClients.Remove(client);
 }
Exemplo n.º 4
0
 public void AddRadioClient(IRadioClient client)
 {
     RadioClients.AddLast(client);
 }