コード例 #1
0
ファイル: Playlist.cs プロジェクト: i-e-b/JWSilverlight
        void ParseXSPF(XDocument doc)
        {
            Items.Clear();
            var tracks = doc.Descendants().Where(d=>d.Name.LocalName == "track");

            foreach (var track in tracks) {
                var playItem = new PlaylistItem(Items);

                playItem.Title = getContent(track, "title");

                var href = getContent(track, "location"); if (href == null) continue;
                playItem.MediaSource = new Uri(href, UriKind.RelativeOrAbsolute).ForceAbsoluteByPage();

                double dur;
                if (double.TryParse(getContent(track, "duration"), out dur)) {
                    playItem.StopPosition = dur / 1000.0;
                }

                var thumb = getContent(track, "image");
                if (thumb != null)
                    playItem.ThumbSource = new Uri(thumb, UriKind.RelativeOrAbsolute).ForceAbsoluteByPage();

                playItem.Description = getContent(track, "annotation");

                Items.Add(playItem);
            }
            if (PlaylistChanged != null) PlaylistChanged(this, null);
            OnPlaylistLoaded(null);
        }
コード例 #2
0
ファイル: Playlist.cs プロジェクト: i-e-b/JWSilverlight
        void ParseAsx(XDocument doc)
        {
            Items.Clear();
            var entries = doc.Descendants("ENTRY");

            foreach (var entry in entries) {
                if (!(entry.Descendants("REF").Count() > 0)) continue;
                var playItem = new PlaylistItem(Items);

                if (entry.Descendants("TITLE").FirstOrDefault() != null)
                    playItem.Title = entry.Descendants("TITLE").First().Value;

                var href = entry.Descendants("REF").First().Attribute("HREF");
                if (href == null) continue;

                playItem.MediaSource = new Uri(href.Value, UriKind.RelativeOrAbsolute).ForceAbsoluteByPage();

                Items.Add(playItem);
            }
            if (PlaylistChanged != null) PlaylistChanged(this, null);
            OnPlaylistLoaded(null);
        }
コード例 #3
0
 /// <summary>
 /// Inserts an item into the collection.
 /// </summary>
 /// <param name="index">Index to insert the item at.</param>
 /// <param name="item">Item to insert.</param>
 protected void InsertItem(int index, PlaylistItem item)
 {
     item.PropertyChanged += item_PropertyChanged;
     base.InsertItem(index, item);
 }
コード例 #4
0
ファイル: Playlist.cs プロジェクト: i-e-b/JWSilverlight
        public void ParseJSON(string jsonObject)
        {
            var value = (JsonArray)JsonValue.Parse(jsonObject);
            if (value == null) return;

            Items.Clear();
            foreach (JsonObject item in value) {
                if (!item.ContainsKey("file")) continue;
                var playItem = new PlaylistItem(Items);

                foreach (var key in item.Keys) {
                    switch (key) {
                        case "autoplay":
                            AutoPlay = bool.Parse(item[key]);
                            break;
                        case "file":
                            var fileUrl = ((string)item[key]);
                            playItem.MediaSource = new Uri(fileUrl, UriKind.RelativeOrAbsolute).ForceAbsoluteByPage();
                            break;
                        case "image":
                            var thumbUrl = ((string)item[key]);
                            playItem.ThumbSource = new Uri(thumbUrl, UriKind.RelativeOrAbsolute).ForceAbsoluteByPage();
                            break;
                        case "duration":
                            playItem.StopPosition = getNumber(item[key]);
                            break;
                        case "start":
                            playItem.ResumePosition = getNumber(item[key]);
                            break;
                        case "title":
                            playItem.Title = item[key];
                            break;
                        case "description":
                            playItem.Description = item[key];
                            break;
                        case "captions":
                        case "captions.file":
                            var captionUrl = ((string)item[key]);
                            playItem.CaptionSource = new Uri(captionUrl, UriKind.RelativeOrAbsolute).ForceAbsoluteByPage();
                            break;
                        default:
                            playItem.CustomProperties.Add(key, item[key]);
                            break;
                    }
                }

                Items.Add(playItem);
            }
            if (PlaylistChanged != null) PlaylistChanged(this, null);
            OnPlaylistLoaded(null);
        }
コード例 #5
0
        public void ParseJSON(string jsonObject)
        {
            var value = (JsonArray)JsonValue.Parse(jsonObject);

            if (value == null)
            {
                return;
            }

            Items.Clear();
            foreach (JsonObject item in value)
            {
                if (!item.ContainsKey("file"))
                {
                    continue;
                }
                var playItem = new PlaylistItem(Items);

                foreach (var key in item.Keys)
                {
                    switch (key)
                    {
                    case "autoplay":
                        AutoPlay = bool.Parse(item[key]);
                        break;

                    case "file":
                        var fileUrl = ((string)item[key]);
                        playItem.MediaSource = new Uri(fileUrl, UriKind.RelativeOrAbsolute).ForceAbsoluteByPage();
                        break;

                    case "image":
                        var thumbUrl = ((string)item[key]);
                        playItem.ThumbSource = new Uri(thumbUrl, UriKind.RelativeOrAbsolute).ForceAbsoluteByPage();
                        break;

                    case "duration":
                        playItem.StopPosition = getNumber(item[key]);
                        break;

                    case "start":
                        playItem.ResumePosition = getNumber(item[key]);
                        break;

                    case "title":
                        playItem.Title = item[key];
                        break;

                    case "description":
                        playItem.Description = item[key];
                        break;

                    case "captions":
                    case "captions.file":
                        var captionUrl = ((string)item[key]);
                        playItem.CaptionSource = new Uri(captionUrl, UriKind.RelativeOrAbsolute).ForceAbsoluteByPage();
                        break;

                    default:
                        playItem.CustomProperties.Add(key, item[key]);
                        break;
                    }
                }

                Items.Add(playItem);
            }
            if (PlaylistChanged != null)
            {
                PlaylistChanged(this, null);
            }
            OnPlaylistLoaded(null);
        }