I need some help trying to make a Windows Phone 8.1 app.
i'm trying to play a shoutcast stream using a XAML media element. i've got it working in a Windows 8 Store application with the following code:
<MediaElement x:Name="media" Source="http://37.187.79.56:3078/listen.pls;" Width="300" AudioCategory="BackgroundCapableMedia" CurrentStateChanged="MusicPlayer_CurrentStateChanged" />
but for Windows phone it isn't working. atleast in my emulator but i have no physical device to test but the emulator plays Cortana sounds so it should play this.
Can someone help me get a solution? Thanks in advance.
You can't play .pls files in WP8, just these media codecs listed in this page . To stream a shoutcast radio, you will need to use Shoutcast MediaStreamSource . You can check a sample here . Hope it helps.
.pls playlist is not supported in windows media element we have to parse the content and get the stream urls, here i pass a pls url to function and get all stream urls as list we can point media element source to any url and will play the radio
public static async Task<List<string>> GetStreamsFromPLSUrl(string url)
{
var httpClientHandler = new HttpClientHandler { UseDefaultCredentials = false, AllowAutoRedirect = true };
HttpClient httpClient = new HttpClient();
try
{
HttpResponseMessage response = await httpClient.GetAsync(url);
response.EnsureSuccessStatusCode();
TextReader tr = new StreamReader(await response.Content.ReadAsStreamAsync());
List<string> Streamurls = new List<string>();
string line;
while ((line = tr.ReadLine()) != null)
{
if (line.Substring(0, 4).Equals("File"))
Streamurls.Add(line.Substring(6));
}
return (Streamurls);
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine(ex.Message + "/n" + ex.InnerException);
return null;
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.