title: MP3 streaming in C# .NET 4.5.1 MVC 5.2.2 on Samsung 6S
body: <p>I have to use a TTS (Text to Speak) SaaS from <a href="http://www.readspeaker.com/" rel="nofollow noreferrer">ReadSpeaker</a> in order to add audio to the application that I am developing. </p>
  
  <p>Now the basic SCAPI account that we are currently using has a basic setup were you simply set a URL and get a MP3 stream back that we need to output. Because the service key is in the URL we can't use it in the front end so we need to stream the files through our servers.</p>
  
  <p>Everything worked fine until I tested the development code on the Samsung 6S. Where it did not play at all, however the services own link works i.e. this works:</p>
  
  <pre><code>&lt;audio controls&gt;
      &lt;source 
          src="http://tts.readspeaker.com/a/speak?key=[ServiceKey]&amp;lang=en_uk&amp;voice=Female01&amp;audioformat=mp3&amp;volume=200&amp;text=test text 2"
          type="audio/mp3"&gt;
          Your browser does not support the audio element.
  &lt;/audio&gt;
  </code></pre>
  
  <p>while the exact same code through our servers does not on Samsung 6S with the same link as the stream source in the controller.</p>
  
  <p>I've gone through several different ways of streaming the file on the server but simply fallen flat each time in Samsung 6S (brand new out of the box no mods).</p>
  
  <p>Here is the code I have used.</p>
  
  <p>Void controller:</p>
  
  <pre><code>string url = "http://tts.readspeaker.com/a/speak?key=[ServiceKey]&amp;lang=en_uk&amp;voice=Female01&amp;audioformat=mp3&amp;volume=200&amp;text=test text 2";
  
  HttpWebRequest HttpWRequest = (HttpWebRequest)WebRequest.Create(url);
  HttpWebResponse response = (HttpWebResponse)HttpWRequest.GetResponse();
  
  Stream stream = response.GetResponseStream();
  
  MemoryStream ms = new MemoryStream();
  stream.CopyTo(ms);
  
  Response.AddHeader("Content-Type", response.ContentType);
  Response.AddHeader("Content-Length", response.ContentLength.ToString());
  Response.AddHeader("Access-Control-Allow-Origin", "*");
  Response.AddHeader("Connection", "close");
  
  Response.Flush();
  
  audioData = ms.ToArray();
  Response.BinaryWrite(audioData);
  
  Response.End();
  </code></pre>
  
  <p>Standard <code>FileStreamResult</code> where I take the above code's MemoryStream and send through it i.e. with a FileStreamResult controller instead of setting the headers manually:</p>
  
  <pre><code>return new FileStreamResult(ms, response.ContentType);
  </code></pre>
  
  <p>and <a href="https://stackoverflow.com/questions/13265392/the-downloaded-file-as-stream-in-controller-asp-net-mvc-3-will-automatically-d">even a modified FileStreamResult I found here</a> that allows for actual streaming of the URL without the need to download it to the server.</p>
  
  <p>I've also used this method to get the byte data from ReadSpeaker:</p>
  
  <pre><code>byte[] audioData;
  using (WebClient client = new WebClient())
  {
      audioData = client.DownloadData("http://tts.readspeaker.com/a/speak?key=[ServiceKey]&amp;lang=en_uk&amp;voice=Female01&amp;audioformat=mp3&amp;volume=200&amp;text=test text 2");
  }
  </code></pre>
  
  <p>And then myriad of ways to output it, but always the result is the same, works fine on everything else (even IE7, not with audio tags, but still) but not with Samsung 6S.</p>
  
  <p>I do not know I must be missing something very basic here, because everything I've tried works just fine on everything else but on the Samsung 6S nothing. Even on other high end Androids like the LG G4 it works but on the 6S... nothing, jet the direct service link in an Audio tag works just fine?</p>
  
  <p>So I know I must be doing something wrong here, any ideas?</p>