コード例 #1
0
        /// <summary>
        /// 从网络上获取频道列表
        /// </summary>
        /// <returns>获取到的频道列表</returns>
        /// <exception cref="HttpRequestException">
        /// 获取频道列表时失败。
        /// </exception>
        /// <exception cref="InvalidDataException">
        /// 数据格式有误。
        /// </exception>
        public static async Task <IEnumerable <Channel> > GetChannelsAsync()
        {
            using (HttpClient client = new HttpClient())
            {
                var uri = new Uri("http://comic.sjtu.edu.cn/vlc/pl_xspf.asp");
                HttpResponseMessage response = await client.GetAsync(uri, HttpCompletionOption.ResponseContentRead);

                if (!response.IsSuccessStatusCode)
                {
                    throw new HttpRequestException(string.Format("HTTP {0}", response.StatusCode.ToString()));
                }

                using (var xmlStream = await response.Content.ReadAsStreamAsync())
                {
                    XDocument xDocument = await XDocument.LoadAsync(xmlStream, LoadOptions.None, CancellationToken.None);

                    Xspf xspf = new Xspf(xDocument, true);
                    return(xspf.TrackList
                           .Where(xspfTrack => xspfTrack.Location.Scheme == "http" || xspfTrack.Location.Scheme == "https")
                           .Select(xspfTrack =>
                                   new Channel
                    {
                        Name = xspfTrack.Title,
                        Url = xspfTrack.Location.ToString()
                    }));
                }
            }
        }
コード例 #2
0
ファイル: UnitTest.cs プロジェクト: taoyouh/XspfOpener
        public async Task Load()
        {
            var file = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///TestFiles/comic.xspf"));

            using (Stream stream = await file.OpenStreamForReadAsync())
                xspf = Xspf.Load(stream);
        }
コード例 #3
0
        /// <summary>
        /// 从本地文件中获取频道列表
        /// </summary>
        /// <returns>获取到的频道列表</returns>
        public static async Task <IEnumerable <Channel> > GetChannelsFallbackAsync()
        {
            var file = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///Contents/fallback.xspf"));

            using (var xmlStream = await file.OpenStreamForReadAsync())
            {
                XDocument xDocument = await XDocument.LoadAsync(xmlStream, LoadOptions.None, CancellationToken.None);

                Xspf xspf = new Xspf(xDocument, true);
                return(xspf.TrackList
                       .Where(xspfTrack => xspfTrack.Location.Scheme == "http" || xspfTrack.Location.Scheme == "https")
                       .Select(xspfTrack =>
                               new Channel
                {
                    Name = xspfTrack.Title,
                    Url = xspfTrack.Location.ToString()
                }));
            }
        }
コード例 #4
0
        protected override async void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);
            if (xspf == null)
            {
                try
                {
                    file = e.Parameter as StorageFile;
                    using (Stream stream = await file.OpenStreamForReadAsync())
                        xspf = Xspf.Load(stream);
                    displayList.DataContext = xspf.TrackList;

                    var mru = StorageApplicationPermissions.MostRecentlyUsedList;
                    mru.Add(file);
                }
                catch
                {
                    MessageDialog msgDialog = new MessageDialog("打开文件失败");
                }
            }
        }