![](/img/trans.png)
[英]How to play background music in windows phone 8.1 with xaml and c#?
[英]Play .pls file with XAML media element Windows Phone 8.1
我需要一些幫助來嘗試制作Windows Phone 8.1應用程序。
我正在嘗試使用XAML媒體元素播放廣播流。 我已經使用以下代碼在Windows 8 Store應用程序中運行它:
<MediaElement x:Name="media" Source="http://37.187.79.56:3078/listen.pls;" Width="300" AudioCategory="BackgroundCapableMedia" CurrentStateChanged="MusicPlayer_CurrentStateChanged" />
但對於Windows Phone,它無法正常工作。 我的模擬器中至少有一個,但我沒有要測試的物理設備,但模擬器播放的是Cortana聲音,因此應該播放。
有人可以幫我解決問題嗎? 提前致謝。
你不能在WP8播放.PLS文件中列出的只是這些媒體編解碼器這個頁面 。 要流式傳輸廣播廣播,您將需要使用Shoutcast MediaStreamSource 。 您可以在此處查看樣本。 希望能幫助到你。
Windows媒體元素不支持.pls播放列表,我們必須解析內容並獲取流url,這里我將一個pls url傳遞給函數並獲取所有流url作為列表,我們可以將媒體元素源指向任何url,然后播放無線電
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;
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.