Интернет радио на C# Unity3D

Узнай цену своей работы

Формулировка задачи:

Всем привет, возможно ли в Unity3D написать на C# интернет радио (воспроизведение аудио потока) а потом скомпилировать в приложение под андроид ? Если это все же реально, то подскажите куда копать пожалуйста.

Решение задачи: «Интернет радио на C# Unity3D»

textual
Листинг программы
  1. private static async Task Play()
  2.         {
  3.             using (WebClient wcDownload = new WebClient())
  4.             {
  5.                 // Create a request to the file we are downloading
  6.                 WebRequest webRequest = (HttpWebRequest)WebRequest.Create("http://media.vmariel.ru:8000/puls");
  7.                 // Set default authentication for retrieving the file
  8.                 webRequest.Credentials = CredentialCache.DefaultCredentials;
  9.                 // Retrieve the response from the server
  10.                 WebResponse webResponse = (HttpWebResponse)webRequest.GetResponseAsync().Result;
  11.                 // Ask the server for the file size and store it
  12.                 Int64 fileSize = webResponse.ContentLength;
  13.  
  14.                 // Open the URL for download
  15.                 System.IO.Stream strResponse = wcDownload.OpenRead(new System.Uri("http://media.vmariel.ru:8000/puls"));
  16.  
  17.  
  18.                 // It will store the current number of bytes we retrieved from the server
  19.                 int bytesSize = 0;
  20.                 // A buffer for storing and writing the data retrieved from the server
  21.                 byte[] downBuffer = new byte[131072];
  22.                 // Loop through the buffer until the buffer is empty
  23.                 AudioTrack audioTrack = new AudioTrack(
  24.                     // Stream type
  25.                     Android.Media.Stream.Music,
  26.                     // Frequency
  27.                     48000,
  28.                     // Mono or stereo
  29.                     ChannelConfiguration.Stereo,
  30.                     // Audio encoding
  31.                     Android.Media.Encoding.Pcm16bit,
  32.                     // Length of the audio clip.
  33.                     downBuffer.Length,
  34.                     // Mode. Stream or static.
  35.                     AudioTrackMode.Stream);
  36.  
  37.                 audioTrack.Play();
  38.                 while ((bytesSize = strResponse.Read(downBuffer, 0, downBuffer.Length)) > 0)
  39.                 {
  40.                     await audioTrack.WriteAsync(downBuffer, 0, downBuffer.Length);
  41.                 }
  42.  
  43.             }
  44.         }

ИИ поможет Вам:


  • решить любую задачу по программированию
  • объяснить код
  • расставить комментарии в коде
  • и т.д
Попробуйте бесплатно

Оцени полезность:

7   голосов , оценка 3.857 из 5

Нужна аналогичная работа?

Оформи быстрый заказ и узнай стоимость

Бесплатно
Оформите заказ и авторы начнут откликаться уже через 10 минут