2014-07-24 143 views
0

我需要一些帮助才能制作Windows Phone 8.1应用程序。使用XAML媒体元素播放.pls文件Windows Phone 8.1

我正在尝试使用XAML媒体元素播放shoutcast流。我知道了在用下面的代码在Windows 8 Store应用程序的工作:

<MediaElement x:Name="media" Source="http://37.187.79.56:3078/listen.pls;" Width="300" AudioCategory="BackgroundCapableMedia" CurrentStateChanged="MusicPlayer_CurrentStateChanged" />

,但对于Windows手机它不能正常工作。至少在我的模拟器,但我没有物理设备来测试,但模拟器播放Cortana的声音,所以它应该玩这个。

有人可以帮我解决问题吗? 在此先感谢。

回答

2

您不能在WP8中播放.pls文件,只需在this page中列出的这些媒体编解码器。 要播放shoutcast收音机,您需要使用Shoutcast MediaStreamSource。你可以检查一个样本here。希望能帮助到你。

0

.pls播放列表不支持在windows media元素中我们必须解析内容并获取流url,在这里我传递一个url函数并获取所有流url作为列表我们可以将media元素源指向任何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; 
     } 
    } 
+0

你能告诉我们如何设置源到MediaElement吗?谢谢! –

相关问题