Reading problems from the Live Audio feed over HTTP in Windows Phone 8.1

I am experimenting with some problems while developing a Windows Phone 8.1 application in C #, which is trying to read streams of Internet audio from different servers of the radio stream.

Among the methods for setting the source of the background audio player, I have successfully proved the MediaPlayer.SetUriSource method, but, unfortunately, the media player is experimenting with errors when playing audio streams with shoutcast metadata.


In particular, the Audio Player eventually stops playing when reading the cry stream.


For this reason, I tried to use the setStreamSource method, establishing an HTTP connection with the audiostreaming server and requesting the required stream for playback, but, unfortunately, the application can only read the first 64 Kbytes of the received audio stream. After that, the thread that manages the thread request dies without providing errors or debugging information.

I would like to add that I tried a regular console application with similar code, and it worked fine!

Here are some examples of how I executed a thread request:

var HClient = new HttpClient();
HttpResponseMessage response = await HClient.GetAsync(streamUrl,HttpCompletionOption.ResponseHeadersRead);
_dataStream = await response.Content.ReadAsStreamAsync();


HttpWebRequest request = (HttpWebRequest)WebRequest.Create(streamUrl);
HttpWebResponse response = (HttpWebResponse) await request.GetResponseAsync();
_dataStream = response.GetResponseStream();


 HttpClient hcb = new HttpClient();
_dataStream = await hcb.GetStreamAsync(streamUrl);


var request = new HttpRequestMessage(HttpMethod.Get, streamUrl);
HttpResponseMessage response = await hcb.SendAsync(request, HttpCompletionOption.ResponseHeadersRead);
_dataStream = await response.Content.ReadAsStreamAsync();

The result is the same in all cases: I get a short piece of the audio stream (about 5-8 seconds), which I can play and hear, and after a few seconds the stream stops. I managed to count the number of bytes that I could read from the stream, and this is 65536 in all cases.

+4

Source: https://habr.com/ru/post/1545832/


All Articles